Results 1 to 10 of 10
  1. #1
    Join Date
    Apr 2002
    Location
    Denver, Colorado
    Posts
    269

    C++: Currency conversions

    Hi all,

    Ok, I'm supposed to write a program that takes an amount of money, what type of currency it is (there will be a list printed out for the user to select from), and take the amount of money, and convert it to the value of another countries currency (once again a list will be provided), all using at least one switch statement.

    Any ideas?

    _dhoss

  2. #2
    If I may ask, why C++?
    Advanced Forum Hosting
    http://www.boardnation.com
    Easily build a community today!

  3. #3
    Join Date
    Mar 2004
    Posts
    4
    soundz like your homework, lol

    and it sounds easy

  4. #4
    Join Date
    Apr 2002
    Location
    Denver, Colorado
    Posts
    269
    Homework,yes, easy, yes, but I'm desperately trying to figure out an EFFICIENT way to do it, so could we cut the "sounds easy" crap and help and just lend a hand?

    Thanks.

  5. #5
    Join Date
    Feb 2004
    Posts
    772
    Hi ,

    I have written a C Program to find the Currency Conversion. Have a look into this...

    ------------------------------------------------------------------------------------
    #include <io.h>
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <system.h>
    #include <ctype.h>

    int main (void)
    {
    float EUR = 0.80273; /* Amount of Euro Dollars to one US Dollar */
    float CHF = 1.25879; /* Amount of Suisse Franc to one US Dollar*/
    float GPB = 0.54880; /* Amount of British Pound to one US Dollar*/
    float CAD = 1.32904; /* Amount of Canadian Dollar to one US Dollar*/
    float AUD = 1.31463; /* Amount of Australian Dollar to one US Dollar*/
    float money;
    float total;
    char charentered;
    while (choice != '5')
    {


    printf("\nCurrency Conversion\n\n"); /* Displays program title*/
    /* The next lines present the user with the choices of currencies available
    and it asks to select one of them*/
    printf("Enter 1 for Euro Dollars\n");
    printf("Enter 2 for Suisse Francs\n");
    printf("Enter 3 for British Pounds\n");
    printf("Enter 4 for Canadian Dollars\n");
    printf("Enter 5 for Australian Dollars\n");
    printf("Enter 0 to exit the program\n\n");

    printf("Please select the currency you want to convert US Dollars to:");
    scanf("%c", &charentered);

    if(charentered < '0' || charentered > '5')
    {
    {
    printf("Program will now terminate.Have a nice day\n");
    break;
    }

    printf("\n\nWhat is the amount of US Dollars you want to convert? : ");
    scanf("%f",&money);
    if (isalpha(money))
    {
    printf("\n Sorry, that was not a valid option.\n");
    break;
    }

    if (choice == 1)
    {
    total = money * EUR; /* one US Dollar equals 0.80273 Euro Dollars */
    printf("\nYou will have %f Euro Dollars! \n\n", total);
    }
    else if (choice == 2)
    {
    total = money * CHF; /* one US Dollar equals 1.25879 Suisse Francs */
    printf("\nYou will have %f Swiss Francs! \n\n", total);
    }
    else if (choice == 3)
    {
    total = money * GPB; /* one US Dollar equals 0.54880 British Pounds */
    printf("\nYou will have %f British Pounds! \n\n", total);
    }
    else if (choice == 4)
    {
    total = money * CAD; /* one US Dollar equals 1.32904 Canadian Dollars */
    printf("\nYou will have %f Canadian Dollars! \n\n", total);
    }
    else if (choice == 5)
    {
    total = money * AUD; /* one US Dollar equals 1.31463 Australian Dollars */
    printf("\nYou will have %f Australian Dollars! \n\n", total);
    }
    } /*end of loop*/
    }
    return 0; /* End of program */
    }
    ------------------------------------------------------------------------------------


    Here's the program in C++ - Hope you can modify for your requirements
    Taken for two country conversions - pound and yen

    ------------------------------------------------------------------------------------

    #include

    ///////////////////////////////////////////////////////////////////////

    // The main () function.

    ///////////////////////////////////////////////////////////////////////

    int main()

    {
    double dollar; /*American currency variable*/
    double pound(double x); /*British currency variable.*/
    double yen (double v); /*Japanese currency variable.*/
    char country; /*Country */
    char ans; /*Y/N to run conversion again.*/

    ///////////////////////////////////////////////////////////////////////

    // Begin Loop: Enter dollar amt and country for conversion.

    //////////////////////////////////////////////////////////////////////

    do
    {
    std::cout >dollar;
    std::cout >country;
    cout.setf(ios::fixed);
    cout.setf(ios:howpoint);
    cout.precision(2);
    if (country == 'J')
    {
    yen(dollar);
    cout >ans;
    }
    while(ans == 'y');

    /////////////////////////////////////////////////////////////////////////////

    // End of Loop

    ////////////////////////////////////////////////////////////////////////////
    return 0; /*Return control to operating system.*/
    }

    ////////////////////////////////////////////////////////////////////////////

    // Calculations

    ///////////////////////////////////////////////////////////////////////////

    double pound(double dollar)
    {
    double temp;
    temp = dollar/1.487;
    return temp;
    }

    double yen(double dollar)
    {
    double temp;
    temp = dollar/0.00955;
    return temp;
    }

    ------------------------------------------------------------------------------------
    Hope this will resolve your problem.

    Regards,

    Bright

  6. #6
    Join Date
    Apr 2002
    Location
    Denver, Colorado
    Posts
    269
    fantastic, but I need a switch statement in there.

  7. #7
    Originally posted by acidhoss
    fantastic, but I need a switch statement in there.
    No one is just going to do your homework for you. If you understand how switch works you should easily be able to modify the posted code to use it. Otherwise find a tutorial on it.
    Advanced Forum Hosting
    http://www.boardnation.com
    Easily build a community today!

  8. #8
    Join Date
    Apr 2002
    Location
    Denver, Colorado
    Posts
    269
    I realize that, the whole point of the question was to see how to do it with a SWITCH statement. The whole REASON I posted here was because I couldn't figure out a way to integrate a switch statement into the code. I'm pretty sure I made that clear up above on the original post.

  9. #9
    Join Date
    Apr 2003
    Posts
    959
    OMG! i just started to learn VB!!!
    is killing me already!

  10. #10
    Join Date
    Apr 2002
    Location
    Denver, Colorado
    Posts
    269
    Wow, cool, and seeing as how I got the problem solved, I reckon we can close this thread.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •