Click to See Complete Forum and Search --> : Currency conversion program


aircuda
June 1st, 2002, 01:09 PM
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;
}

wake
June 1st, 2002, 02:23 PM
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:
#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;
}