My do-while loop isnt reading the entire bracketed area after 1 run (meaning the first run it actually reads the cin line). It only reads my cout line and skips the other lines. Why is this?
Im pretty new so if my technique is a little unorthodox please forgive me. I simply am trying to answer this question. After fixing it then make suggestions on proper code building would be helpful also unless proper code building is necessary to fix my problem :)
int main()
{
int menu1 = 0;
while(menu1 != 'q')
{
cout << "\t Help\t Smallest \t Largest \t Quit" << endl;
cin >> menu1;
GetMenu(menu1);
}
return 0;
}
Its a simple switch / case but it doesnt do anything in it either. I ran the line by line debug and it actually goes to get menu but it doesnt abide by all the rules i have set.
void GetMenu(int x)
{
switch(x)
{
case 'h':
case 'H':
help();
break;
case 's':
case 'S':
smallest();
break;
case 'l':
case 'L':
largest();
break;
case 'q':
case 'Q':
cout << "Exiting please wait...";
}
return;
}
I had everything together in main and it was doing the same thing... onlyr reading couts, ignoring my switch, cin and others... if i add another cout... it reads it but if i add 2 or 3 cin's it doesnt read it....infinite loop of ONLY cout...
You're doing a cin to an int. I'm surprised you even got to GetMenu. cin is going to choke on alpha input to an int. Change your declaration of menu1 to a char.
char menu1 = 0;
Please use code tags (the <> formatting button) rather than quote when posting code.