Hi all
When this is run, a menu of 2 choices is presented. The user has to select either 1 or 2.
Now if the user mistakenly select, for example 3 or 4, which is not on the menu, the program still runs.
I'd like to make it that upon pressing other than 1 or 2, the program gives the menu again.
If I need to use a do-while inside of a do-while, it seems awkward.
How would I do it?
Thanx :)
Code:#include <iostream.h>
#include <stdlib.h>
int main()
{
char convert;
do
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
double usd, rm;
int choice;
cout << "What would you like to do?\n"
<< "1. Convert USD to RM.\n"
<< "2. Convert RM to USD." << endl << endl;
//char choice;
cin >> choice;
cout << endl;
if (choice == 1)
{
cout << "Enter the value in USD you would like to convert: ";
cin >> usd;
rm = usd * 3.5;
cout << "USD " << usd << " is equal to RM " << rm << endl << endl;
}
if (choice == 2)
{
cout << "Enter the value in RM you would like to convert: ";
cin >> rm;
usd = rm / 3.5;
cout << "RM " << rm << " is equal to USD " << usd << endl << endl;
}
//else
cout << "Would you like to convert currency again?\n";
cin >> convert;
}
while (convert == 'y' || convert == 'Y');
cout << "Thank you\n";
system("PAUSE");
return 0;
}