It is a menu driven program and works completely fine when an int is passed to the variable options but runs into an infinite loop when char is passed.
int main(){
while(true){
int options{0};
cout<<"\nYour choice >>";
cin>>options; //this line doesnt execute after any char(say r) is given as an input
switch(options){
case 1:login();break;
case 2:signup();break;
case 3:return 0;
default:cerr<<"Please enter a valid choice"<<endl;
}
}
txt.close();
return 0;
} I tried to debug and here is the problem
Breakpoint 1, main () at main.cpp:16 16 cin>>options; (gdb) p options $1 = 0 (gdb) c Continuing. Your choice >>r
Breakpoint 2, main () at main.cpp:17 17 switch(options){ (gdb) p options $2 = 0 (gdb) c Continuing.
Breakpoint 3, main () at main.cpp:21 21 default:cerr<<"Please enter a valid choice"<<endl; (gdb) p options $3 = 0 (gdb) c Continuing. Please enter a valid choice
Breakpoint 1, main () at main.cpp:16 16 cin>>options; (gdb) c Continuing.
Breakpoint 2, main () at main.cpp:17 17 switch(options){ (gdb) Quit (gdb)
After line 16 its going to line 17 without asking for input from user