# Does anyone know how to do this?

• 06-03-2002
ob1cnobe
Does anyone know how to do this?
I am trying to expand on a currency conversion code that I wrote I'm tryin to create a menu (using a loop) that allows the user to choose which currency and the amount of the foreign currency they wish to convert to US dollars. The program will continue running u.ntil the user select "Exit" option. Below is the code I been done so far
#include<iostream.h>

double amount = 0.0; /*Stores user input*/

int main()
{
cout<<"Currency Conversion"<<endl;

cout<<"--------------------\n";

cout<<"Enter the amount in US Dollar: "; /*Prompt user for amount*/

cin>>amount; /* Read in the amount*/

/*Convert the amount to each currency type and print it out*/

cout<<amount<<" US Dollars = "<<amount/0.6072<<" Swiss Francs\n";
cout<<amount<<" US Dollars = "<<amount/1.4320<<" British Pounds\n";
cout<<amount<<" US Dollars = "<<amount/0.0081<<" Japanese Yens\n";
cout<<amount<<" US Dollars = "<<amount/0.6556<<" Canadian Dollars\n";
cout<<amount<<" US Dollars = "<<amount/0.8923<<" Euros\n";

}
• 06-03-2002
hostensteffa
I've always used a do while statement along with some switches
but there's a few ways to do it. Most will say to make it so the exit just runs to the end of the main function and let it quit safely, in lengthy programs, i prefer to use the exit command.

ex:
Code:

``` int selection; do {     cout<< " (1)  Do this \n";     cout<<"  (2)  Do that \n";     cout<<"  (3)  Exit \n"; }while(selection > 3 || selection < 1); switch(selection) {     case 1:         cout<<" bla \n\n";     case 2:          cout<<"bla bla \n\n";     case 3:         exit(0); } //end switch```
this is not the most proper way it's just how I usually do it. Hope this helps you.
• 06-04-2002
Sebastiani
Just face it: writing a menu can be drudgerous, but if you spend a little time on it you may find that it's not so hard. It is the responsibility of every programmer to be able to master them. And you will get more help if you were more productive. I can write out a thousand lines of code per day...just how many have you done? If you just sit there waiting for the code to be written for you, you will just become more and more lazy. You just have to practice.