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";
}
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.