Well, I create the void function, let’s say `Press1`. So I write:
1 2 3 4 5 6
void Press1 ( ) {
int a;
cout << "Please press 1"<< endl;
cin >> a;
if (a==1) {
cout << "congrats, you pressed 1"<< endl;}else{cout << "I said PRESS 1!" << endl;}
Well, so far so good. But now, I want to make the user to be able to cin a again. So I create a while loop:
1 2 3 4 5 6 7 8 9
void Press1 ( ) {
int a;
cout << "Please press 1" << endl;
while (a!=1)
{
cin >> a;
if (a==1) {
cout << "congrats, you pressed 1" << endl;}else{cout << "I said PRESS 1!" << endl;}
}
Now, the Programm somehow just skips the cin >> a; , so the while loop doesn`t stop. "I said PRESS 1" now gets repeated until my PC busts. The same thing happens if I use a recursion instead of the while loop.