Thread: simple currency conversion problem

  1. #1
    Registered User
    Join Date
    Aug 2002

    Exclamation simple currency conversion problem

    I am doing a program that is to expand the "Currency Conversion" program to accept a currency amount for one currency from the user, which is error checked as a valid entry, and then display its equivalency in US dollars. Insert comments in the program to document the program internally. Be sure not to over design the program, in particular include requirements to be added to the program in the subsequent weeks. The thing is when I do this from what i've wrote then it gives me a bad input error at the line to enter today's exchange rate. I know that it should be a string and not long but i'm not really sure how to change that. Can anyone tell this woman who's been up for 72 hours straight trying to figure it out where the heck the snake is that should've already bitten her? Any help is greatly appreciated!!

    #include <iostream.h>
    #include <string>
    using namespace std;

    int main ()
    //enter input items
    long currency = 0.0;
    cout << "Enter Currency: ";
    cin >> currency;
    switch (currency)
    case 'Euro':
    case 'euro': cout << "Euro" << endl;
    case 'FF':
    case 'ff': cout << "FF" << endl;
    case 'DM':
    case 'dm': cout << "DM" << endl;
    case 'GBP':
    case 'gbp': cout << "GBP" << endl;
    case 'Yen':
    case 'yen': cout << "Yen" << endl;

    } //end switch
    cout << "Enter Today's Exchange Rate:";
    cin. >> currency;
    if (
    { cout << "Error: bad input";
    return 1;
    }//validation of input

    float rate = 0.0;
    bool more = true;
    cout << "Enter USD amount:"<<"\n";
    while (more)

    float usDollar = 0.0;
    if (cin >> usDollar)
    if (usDollar <= 0)//test for sentinel
    more = false;
    currency = usDollar * (cin, currency);
    cout << currency << "";
    return 0;
    } //end of main function

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Northern Virginia/Washington DC Metropolitan Area
    After just a quick look:

    1) It appears you are using a long data type variable to store the currency type, this should probably be a string type instead.
    2) You can't use non-integral data types in your switch statement. This means no case 'DM'. If you make the above change I suggested, then this whole switch statement should be made into a if, else-if type of statement.
    3) This may be a typo, but in your code there is a cin. piece where the period should not be there.
    4) You should be using the <iostream> header instead of the one you have with the .h extension. The using namespace std; line takes care of any namespace problems and using this new header will match better with the <string> header you are including.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Aug 2002
    You were right the . was a for the long to switch i'm not sure how to go about changing that...and i got rid of the .h that's the way i had it in the beginning...should have stuck with my first instinct...any suggestions on the long to switch conversion?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  2. Simple Display Problem?
    By portable in forum C Programming
    Replies: 4
    Last Post: 01-03-2008, 06:53 AM
  3. problem with A simple modeless messagebox
    By hanhao in forum C++ Programming
    Replies: 8
    Last Post: 07-05-2005, 11:18 PM
  4. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  5. Currency Conversion Program
    By kgraw21 in forum C Programming
    Replies: 5
    Last Post: 04-19-2002, 08:39 AM