CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2001
    Location
    Florida, USA
    Posts
    2

    Currency conversion program

    I'm trying to get the following program to convert USDOLLARS to a foreign currency using the conversion rate of 1.53353. Currently the output shows th conversion rate, not the currency amount.

    Will someone please tell me what I need to modify to get the program to function?

    Thanks,

    aircuda

    //Currency conversion to calculate US dollars to foreign five foreign currencies.

    #include <iostream.h>
    #include <iomanip.h>
    #include <conio.h>

    int main()

    {
    //declare variables
    int USDOLLARS = 1;
    float rate = 1.53353;
    float conversion;
    conversion = USDOLLARS * rate;
    //enter input items
    cout << "Enter number of US dollars to be converted: ";
    cin >> USDOLLARS;
    cout << "Conversion: " << conversion << endl;

    //calculation




    return 0;
    }

  2. #2
    Join Date
    Jun 2002
    Location
    Florida
    Posts
    32
    The reason you're not getting the desired output is because you define conversion as the initial dollar value (1) multiplied by the rate. You need to calculate the conversion after you cin the number of dollars to be converted.

    So something like this:
    Code:
    #include <iostream.h> 
    #include <iomanip.h> 
    #include <conio.h> 
    
    int main() 
    
    { 
    //declare variables 
    int USDOLLARS = 1; 
    float rate = 1.53353; 
    float conversion; 
    //enter input items 
    cout << "Enter number of US dollars to be converted: "; 
    cin >> USDOLLARS; 
    
    conversion = USDOLLARS * rate; // move the conversion 'algo' here.
    
    cout << "Conversion: " << conversion << endl; 
    
    //calculation 
    return 0; 
    }

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured