Help: how to re-present the menu options.

Hi, i am new to programming. Actually i'm new to this subject of Computer Science.
I am trying to make a menu system to give a user 3 choices to choose from, if the user enters an incorrect choice such as 4. The program must produce an error message and RE-PRESENT the menu system. My question is, how do i do this without including the last three statements which you see in my program..

Here is my program.



#include <iostream>

using namespace std;
int main ()
{
int choice;

cout << "Choose one of the following options by using 1 for a), 2 for b) and 3 for c):\n\n";
cout << "a) Convert from base 10 to Binary Coded Decimal \n\n"
<< "b) Convert from base 8 to base 2 \n\n"
<< "c) Quit \n";

cin >> choice;



switch(choice)
{
case 1 :
cout << "a) Convert from base 10 to Binary Coded Decimal \n";
break;
case 2 :
cout << "b) Convert from base 8 to base 2 \n";
break;
case 3 :
cout << "c) Quit \n";
break;
default:
cout <<"ERROR: INVALID INPUT \n\n\n"
<< "a) Convert from base 10 to Binary Coded Decimal \n\n"
<< "b) Convert from base 8 to base 2 \n\n"
<< "c) Quit \n";
}



return 0;
}
Last edited on
Oh, sorry for the mess in my question.
Hi, i'm a newbie too but you can use a do while loop with the menu within the loop

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

int choice;

do {

cout << "Choose one of the following options by using 1 for a), 2 for b) and 3 for c):\n\n";
cout << "a) Convert from base 10 to Binary Coded Decimal \n\n"
<< "b) Convert from base 8 to base 2 \n\n"
<< "c) Quit \n";

cin >> choice;

switch(choice)
{
case 1 :
cout << "a) Convert from base 10 to Binary Coded Decimal \n";
break;
case 2 :
cout << "b) Convert from base 8 to base 2 \n";
break;
case 3 :
cout << "c) Quit \n";
break;
default:
cout <<"ERROR: INVALID INPUT \n\n\n";
}
} while (choice != 100) 


if the user enters 100, the program will automatically exit though.
Last edited on
Thanks a lot earthearth,it works really fine.....
Topic archived. No new replies allowed.