Thraner
12-19-2002, 01:08 PM
Guys, I see no reason why this should go into an endless loop when the user enters a bad value.. Any ideas? I guess what I mean to say is, if it fails the IF statement, it just keeps repeating the error message, without asking the user for another input.
#include <iostream>
#include <string>
using namespace std;
void main()
{
//Title
cout << "Currency Conversion\n";
//Skip a line
cout << "\n";
/*Declare the variables, which later will contain the
equivalents to a US Dollar */
float auDollars = 0.0;
float euEuros = 0.0;
float gbPounds = 0.0;
float caDollars = 0.0;
float jaYen = 0.0;
//Declare a variable for a user to enter an amount of US Dollars
float userDollars = 0.0;
bool calculationDone = false;
//Declare a constant value for US Dollars
const float USDOLLARS = 1.0;
//Compute the equivalents to US Dollars
auDollars = float(USDOLLARS * 1.78380);
euEuros = float(USDOLLARS * 0.998301);
gbPounds = float(USDOLLARS * 0.636951);
caDollars = float(USDOLLARS * 1.55837);
jaYen = float(USDOLLARS * 124.527);
// Output the equivalents to a US Dollar
cout << "$1 US = " << auDollars << " Australian Dollars" << endl;
cout << "$1 US = " << euEuros << " European Euros" << endl;
cout << "$1 US = " << gbPounds << " Great British Pounds" << endl;
cout << "$1 US = " << caDollars << " Canadian Dollars" << endl;
cout << "$1 US = " << jaYen << " Japanese Yen" << endl;
//Error-check the amount of US Dollars the user has entered
while (calculationDone == false)
{
cout << "Please enter an amount of US Dollars" << endl;
userDollars = 0.0;
cin >> userDollars;
if (userDollars > 0)
{
//do and output calculations
cout << userDollars << " US Dollars = " << (userDollars * auDollars) << " Australian Dollars.";
calculationDone = true;
}
//end if
}
//end while
}
#include <iostream>
#include <string>
using namespace std;
void main()
{
//Title
cout << "Currency Conversion\n";
//Skip a line
cout << "\n";
/*Declare the variables, which later will contain the
equivalents to a US Dollar */
float auDollars = 0.0;
float euEuros = 0.0;
float gbPounds = 0.0;
float caDollars = 0.0;
float jaYen = 0.0;
//Declare a variable for a user to enter an amount of US Dollars
float userDollars = 0.0;
bool calculationDone = false;
//Declare a constant value for US Dollars
const float USDOLLARS = 1.0;
//Compute the equivalents to US Dollars
auDollars = float(USDOLLARS * 1.78380);
euEuros = float(USDOLLARS * 0.998301);
gbPounds = float(USDOLLARS * 0.636951);
caDollars = float(USDOLLARS * 1.55837);
jaYen = float(USDOLLARS * 124.527);
// Output the equivalents to a US Dollar
cout << "$1 US = " << auDollars << " Australian Dollars" << endl;
cout << "$1 US = " << euEuros << " European Euros" << endl;
cout << "$1 US = " << gbPounds << " Great British Pounds" << endl;
cout << "$1 US = " << caDollars << " Canadian Dollars" << endl;
cout << "$1 US = " << jaYen << " Japanese Yen" << endl;
//Error-check the amount of US Dollars the user has entered
while (calculationDone == false)
{
cout << "Please enter an amount of US Dollars" << endl;
userDollars = 0.0;
cin >> userDollars;
if (userDollars > 0)
{
//do and output calculations
cout << userDollars << " US Dollars = " << (userDollars * auDollars) << " Australian Dollars.";
calculationDone = true;
}
//end if
}
//end while
}