I have this code, which gives users suggestion to select one of the options in my menu:
char c;
do {
switch(c=getchar()){
case '1':
cout << "Print" << endl;
break;
case '2':
cout << "Search" << endl;
break;
case '3':
cout << "Goodbye!" << endl;
break;
default:
cout << "I have this symbol now: " << c << endl;
break;
}
} while (c != '3');
So, it suppose to to read the character and put us in one of the three options. And it does. But only after I push enter, and well, I can live with that, but it also accepts these string as a valid options:
- dfds2kflds, fdsf3, fds1lkfd
What the hell? I want it to accept only character like this:
- 1, 2, 3 How can I fix it? I am a noob at c++.