Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Currency Conversion C++ program help!

mrn97mrn97 Member Posts: 6
I have written a currency conversion program that is working but I need to input code that will not allow the user to type in a letter, so far I have used while loops that make sure the user does not input a number greater than 6, now I need to modify it to prevent users from typing a letter, right now when I type a letter it loops. Can anyone please give me some help, thanks .

here is the code:

#include


using namespace std;

// Declarations

#define USDvalue 1.00 /* Defines United States Dollar*/
#define CADvalue 0.8681 /* Canadian Dollar*/
#define EURvalue 1.2251 /* Euro*/
#define BPvalue 1.7843 /* British Pound*/
#define JPYvalue 0.008643 /* Japanese Yen*/
#define MXNvalue 0.09509 /* Mexico Peso*/
int GetNum; /* defines input*/
int GetAmt; /* defines conversion input*/
float USrate; /* calculates conversion amount*/



int main()

{
cout << " **Currency Conversion Program**

";
cout << "Please choose a currency conversion rate to view:

";
cout << "1. Candian Dollar to US Dollar.

";
cout << "2. Euro to US Dollar.

";
cout << "3. Mexico Peso to US Dollar.

";
cout << "4. British Pound to US Dollar.

";
cout << "5. Japanese Yen to US Dollar.

";
cout << "6. Exit.

";
cin >> GetNum;

while(GetNum > 6) /* While loop to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}


while ((GetNum > 0 )&&(GetNum < 6)) /* While loop to allow multiple selections*/
{

switch (GetNum) /* Displays 5 currency's and their USD equivilent*/
{

case 1: /*Canadian Dollar*/
cout << "

There are " << CADvalue << " Canadian dollars in one US Dollar.

";
cout << "Please enter amount of CAD to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*CADvalue; /* Calculates the conversion from CAD to USD*/
cout << "

The amount of " << GetAmt <<" Canadian dollars are equal to " << USrate <<" US dollars.

";
cout << "Please enter another selection or enter 6 to exit.

";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}
break;

case 2: /*Euro*/
cout << "

There are " << EURvalue << " Euro's in one US Dollar.

";
cout << "Please enter amount of Euro's to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*EURvalue; /* Calculates the conversion from Euro to USD*/
cout << "

The amount of " << GetAmt <<" Euro's are equal to " << USrate <<" US dollars.

";
cout << "Please enter another selection or enter 6 to exit.

";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}
break;

case 3: /* Mexican Peso*/
cout << "

There are " << MXNvalue << " Mexican Pesos in one US Dollar.

";
cout << "Please enter amount of Mexican Pesos to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*MXNvalue; /* Calculates the conversion from Pesos to USD*/
cout << "

The amount of " << GetAmt <<" Mexican Pesos are equal to " << USrate <<" US dollars.

";
cout << "Please enter another selection or enter 6 to exit.

";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}
break;

case 4: /* British Pound*/
cout << "

There are " << BPvalue << " British Pounds in one US Dollar.

";
cout << "Please enter amount of British Pounds to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*BPvalue; /* Calculates the conversion from British Pounds to USD*/
cout << "

The amount of " << GetAmt <<" British Pounds are equal to " << USrate <<" US dollars.

";
cout << "Please enter another selection or enter 6 to exit.

";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}
break;

case 5: /*Japanese Yen*/
cout << "

There are " << JPYvalue << " Japanese Yen in one US Dollar.

";
cout << "Please enter amount of Japanese Yen to convert: ";
cin >> GetAmt;
USrate = GetAmt*JPYvalue; /* Calculates the conversion from Japanese Yen to USD*/
cout << "

The amount of " << GetAmt <<" Japanese Yen are equal to " << USrate <<" US dollars.

";
cout << "Please enter another selection or enter 6 to exit.

";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "

Error! Please enter a number from 1 to 6.

";
cin >> GetNum;
}
break;

}/* End of switch*/

} /* End of while loop*/

/* Exit message of program*/

cout << "

Thank you for use the Currency Conversion Program.

";
cout << "

Please press any key to exit.

";
cin >> GetNum;

return 0;

}
Sign In or Register to comment.