I'm trying some things out with C++ did it a long time ago and now I'm picking it up again. I'm just trying to make a few things to understand all the loops again.
But now I got this code..
You can choose 3 answers until you got the right one, but the thing is I made a kind of pin(not sure how you call it) but when you enter the wrong answer is goes back to that pin(that pin is at the start of the program).
The thing is, if people answer but a number above 3 it'll say sorry the value must be between 1 and 3.
But when I enter a letter it says the same but gives an infinite loop and doesn't come out of it.
I want that if people answer a character or string that they have to guess ago.
I hope someone could help me with this
Here's the code:
//Menu Chooser #include <iostream> using namespace std; int main() { cout << " Is CodeCall A Great Site\n\n"; cout << "1 -- Yeah Totally!\n"; cout << "2 -- Not Sure..\n"; cout << "3 -- No, it's an awful site!\n"; TryAgain: //this is a kind of pin where you can come back to later in the code int choice; cout << "Choice: "; cin >> choice; //get here the input from the user if (choice == 1) { cout << "You're Totally Right!!\n\n"; } else if (choice ==2) { cout << "I'm Sorry But If You Knew The Forum YOu Wouldn't Have Doubts \n\n"; goto TryAgain; //Here the loop will be transported back to the ping 'TryAgain' } else if (choice == 3) { cout << "Are You Serious?! I'm Sorry That Can't Be Correct...\n\n"; goto TryAgain; } else //this only works when you enter a wrong number. with a char it'll give an infinite loop, why? { cout << "Sorry you must answer a number from 1 to 3\n"; goto TryAgain; } system("pause"); //Pause the program otherwise the program will shut down return 0; }
I Appreciate the help!
//SterAllures
Edited by SterAllures, 05 April 2009 - 11:00 PM.