loop

  • Thread starter Thread starter denis
  • Start date Start date
D

denis

I have I do while ((choice==1)||(choice==2)||(choice==3));
loop where I am sking a user to enter appropriate value
1,2,3. If user enters incorrect value I want then to see
the main menu.
How do I do this?
 
Something like :-

int choice = 0;
while( (choice<1) || (choice>3) )
{
ShowMenu();
choice = GetChoice();
}
 
-----Original Message-----
I have I do while ((choice==1)||(choice==2)||(choice==3));
loop where I am sking a user to enter appropriate value
1,2,3. If user enters incorrect value I want then to see
the main menu.
How do I do this?

.
you may write your code as-
menu: //this is the label of the code
cout<<"choice 1";
cout<<"choice 2";
cout<<"choice 3";
cout<<"enter a choice";
cin>>choice;
if(choice<1 || choice>3)
{
goto menu;
}
while((choice==1) || (choice==2) || (choice==3))
{
statement;
}


IF YOU GET A PROBLEM IN DOING THIS IN C++, I'LL BE PLEASED
TO HANDLE YOUR QUERY
 
sandeep said:
menu: //this is the label of the code
cout<<"choice 1";
cout<<"choice 2";
cout<<"choice 3";
cout<<"enter a choice";
cin>>choice;
if(choice<1 || choice>3)
{
goto menu;
}

I'm not an anti-goto zealot, but the proper spelling of this construct
is do ... while.
 
Back
Top