|
-
June 1st, 2002, 01:09 PM
#1
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;
}
-
June 1st, 2002, 02:23 PM
#2
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|