Thread: Does anyone know how to do this?

  1. #1
    Registered User
    Join Date
    May 2002

    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

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

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


    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
    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.

    int selection;
        cout<< " (1)  Do this \n";
        cout<<"  (2)  Do that \n";
        cout<<"  (3)  Exit \n";
    }while(selection > 3 || selection < 1);
        case 1:
            cout<<" bla \n\n";
        case 2:  
            cout<<"bla bla \n\n";
        case 3:
    } //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
    Waterloo, Texas
    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.
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

Popular pages Recent additions subscribe to a feed