#include<iostream>
using namespace std;
void fun() {
while(1) {
char choice;
cout<<"(D)isplay, (E)xit"<<endl;
start:
cout<<">> ";
cin>>choice;
switch(choice) {
case 'd':
case 'D':
cout<<"hello world"<<endl;
break;
case 'e':
case 'E':
return;
default:
cout<<"INVALID!"<<endl;
goto start;
}
}
}
int main() {
system("clear");
fun();
return 0;
}
This is a simple c++ program. I am faciing following problem:
(D)isplay, (E)xit
>> mnop
INVALID!
>> INVALID!
>> INVALID!
>> INVALID!
>>
The symbol '>>' prompt user to enter a character and with that it give apppropriate result but if entered a string it behaves something like this. I want to know why this happens and how to stop it :)
goto start
, you are within a while loopstring
? If you had used astring
in your code your current issue would not be there