exit do while loop
How can I exit this loop if the choice is 3
Thanks
1 2 3 4 5 6 7 8 9 10 11
|
do
{
cout << "Enter a number between 0 and 2, 3 to end: ";
cin >> choice;
(*f[ choice ])( choice );
if(choice>2)
{
cout << "Program execution completed." << endl;
}
}
while ( ( choice >= 0 ) && ( choice < 3 ) );
|
You can do one of two things:
1.
1 2 3 4 5 6 7 8 9 10 11
|
do
{
cout << "Enter a number between 0 and 2, 3 to end: ";
cin >> choice;
(*f[ choice ])( choice );
if(choice>2)
{
cout << "Program execution completed." << endl;
}
}
while ( ( choice >= 0 ) && ( choice < 2 ) ); //Just don't repeat if the choice is 3
|
2.
1 2 3 4 5 6 7 8 9 10 11 12
|
do
{
cout << "Enter a number between 0 and 2, 3 to end: ";
cin >> choice;
(*f[ choice ])( choice );
if(choice>2)
{
cout << "Program execution completed." << endl;
break; //<- use a break command.
}
}
while ( ( choice >= 0 ) && ( choice < 3 ) );
|
Thanks,I found my error
Last edited on
Topic archived. No new replies allowed.