Help

Well I'm trying to create this one game for my school project but it is supposed to be a "magic" trick a but it will defeat the purpose if you can see the number in the screen so I was wondering if you can amke to not show the input a and c.

#include <iostream>
#include <string>

using namespace std;
int main () {
int a, b, c;
string sg;
sg = "First number is the one you chose the rest are your age.";
cout << "MAGIC Numbers. \n";
cout << "Pick a number from one though ten:";
cin >> a;
a = a * 2;
a = a + 5;
a = a * 50;
cout << "Did your birthday already pass? \n (Enter 1 for yes 2 for no) \n";
cin >> b;
if ( b == 1 ){
a = a + 1761;
}
else {
a = a +1760;
}
cout << "Enter your year of birth: \n";
cin >> c;
a = a - c;
cout << sg << a <<"\n";
system ("pause");
}

Last edited on
You can use getch() to input single character, which will not be displayed over screen.
ch = getch();

And, user don;t need to press enter key here.



Gorav
http://www.kgsepg.com
Thanks
I would use cin.get() instead of getch().
How would you use cin.get() im trying it but cant figure it.

#include <iostream>
#include <string>

using namespace std;
int main () {
int a, b, c;
string sg;

sg = "First number is the one you chose the rest are your age.";
cout << "MAGIC Numbers. \n";
cout << "Pick a number from one though ten:";
cin.get (a); // Here?
a = a * 2;
a = a + 5;
a = a * 50;
cout << "Did your birthday already pass? \n (Enter 1 for yes 2 for no) \n";
cin.get >> b;
if ( b == 1 ){
a = a + 1761;
}
else {
a = a +1760;
}
cout << "Enter your year of birth: \n";
cin.get >> c;
a = a - c;
cout << sg << a <<"\n";
system ("pause");
}

Last edited on
Either:

cin.get(c);
or
c = cin.get();

Note that doing it this way will *not* remove the enters that will be in the buffer from when the user sends you input. You will have to deal with those yourself somehow (probably using cin.ignore()).
Last edited on
Topic archived. No new replies allowed.