Decimals not going to the right place

Hello,

I am writing a program to convert dollars to various currencies. Everything is working, except the final answer is not formatting correctly. The answers are computing correctly (10253.00) but the decimal place is wrong, as it should be 102.53 not 10253.000. How can I fix this?

// This program tells the user how to make change.
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <stdio.h>

using namespace std;

float currency;
float YEN_PER_DOLLAR;
float RAND_PER_DOLLAR;
float SHEKEL_PER_DOLLAR;
float EUROS_PER_DOLLAR;

int main( )
{

// Get currency amount from user.
cout << "Amount of U.S. currency to convert: $ ";
std::cin >> currency;
cout << "\n";
cout << "\n";

// Convert currencies.
YEN_PER_DOLLAR = 102.53 * currency;
RAND_PER_DOLLAR = 14.56 * currency;
SHEKEL_PER_DOLLAR = 3.85 * currency;
EUROS_PER_DOLLAR = 0.90 * currency;

// Display conversions.
cout << "FOREIGN CURRENCIES CONVERTED \n";
cout << "----------------------------" << endl;
cout << "\n";

cout << "$" << currency << " " << "=" << " " << YEN_PER_DOLLAR << " " << "Yen (Japan) \n";
cout << "$" << currency << " " << "=" << " " << RAND_PER_DOLLAR << " " << "Rand (South Africa) \n";
cout << "$" << currency << " " << "=" << " " << SHEKEL_PER_DOLLAR << " " << "Shekel (Israel) \n";
cout << "$" << currency << " " << "=" << " " << EUROS_PER_DOLLAR << " " << "Euros (European Union) \n";

return 0;
}



OUTPUT:
Amount of U.S. currency to convert: $ 100


FOREIGN CURRENCIES CONVERTED
----------------------------

$100.00 = 10253.00 Yen (Japan)
$100.00 = 1456.00 Rand (South Africa)
$100.00 = 385.00 Shekel (Israel)
$100.00 = 90.00 Euros (European Union)
closed account (E0p9LyTq)
Try entering a different US dollar value to be converted, $105 for example, or $55.25. $100 is not a good example.
Im pretty sure the computed value is correct. I just converted 100 bucks to yen on several online converters and they all spit out a value of around 10253.00 yen.
Last edited on
Topic archived. No new replies allowed.