Does anyone know how to do this?

This is a discussion on Does anyone know how to do this? within the C++ Programming forums, part of the General Programming Boards category; I am trying to expand on a currency conversion code that I wrote I'm tryin to create a menu (using ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    15

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

    }

  2. #2
    Registered User
    Join Date
    May 2002
    Posts
    178
    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.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    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.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21