Beginner C/C++

Moderators: None (Apply to moderate this forum)
Number of threads: 5428
Number of posts: 16949

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Currency Conversion C++ program help! Posted by mrn97 on 2 Feb 2006 at 3:36 PM
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 <iostream>


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 << "\t**Currency Conversion Program**\n\n";
cout << "Please choose a currency conversion rate to view:\n\n";
cout << "1. Candian Dollar to US Dollar.\n\n";
cout << "2. Euro to US Dollar.\n\n";
cout << "3. Mexico Peso to US Dollar.\n\n";
cout << "4. British Pound to US Dollar.\n\n";
cout << "5. Japanese Yen to US Dollar.\n\n";
cout << "6. Exit.\n\n";
cin >> GetNum;

while(GetNum > 6) /* While loop to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
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 << "\n\nThere are " << CADvalue << " Canadian dollars in one US Dollar.\n\n";
cout << "Please enter amount of CAD to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*CADvalue; /* Calculates the conversion from CAD to USD*/
cout << "\n\nThe amount of " << GetAmt <<" Canadian dollars are equal to " << USrate <<" US dollars.\n\n";
cout << "Please enter another selection or enter 6 to exit.\n\n";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
cin >> GetNum;
}
break;

case 2: /*Euro*/
cout << "\n\nThere are " << EURvalue << " Euro's in one US Dollar.\n\n";
cout << "Please enter amount of Euro's to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*EURvalue; /* Calculates the conversion from Euro to USD*/
cout << "\n\nThe amount of " << GetAmt <<" Euro's are equal to " << USrate <<" US dollars.\n\n";
cout << "Please enter another selection or enter 6 to exit.\n\n";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
cin >> GetNum;
}
break;

case 3: /* Mexican Peso*/
cout << "\n\nThere are " << MXNvalue << " Mexican Pesos in one US Dollar.\n\n";
cout << "Please enter amount of Mexican Pesos to convert to USD: ";
cin >> GetAmt;
USrate = GetAmt*MXNvalue; /* Calculates the conversion from Pesos to USD*/
cout << "\n\nThe amount of " << GetAmt <<" Mexican Pesos are equal to " << USrate <<" US dollars.\n\n";
cout << "Please enter another selection or enter 6 to exit.\n\n";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
cin >> GetNum;
}
break;

case 4: /* British Pound*/
cout << "\n\nThere are " << BPvalue << " British Pounds in one US Dollar.\n\n";
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 << "\n\nThe amount of " << GetAmt <<" British Pounds are equal to " << USrate <<" US dollars.\n\n";
cout << "Please enter another selection or enter 6 to exit.\n\n";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
cin >> GetNum;
}
break;

case 5: /*Japanese Yen*/
cout << "\n\nThere are " << JPYvalue << " Japanese Yen in one US Dollar.\n\n ";
cout << "Please enter amount of Japanese Yen to convert: ";
cin >> GetAmt;
USrate = GetAmt*JPYvalue; /* Calculates the conversion from Japanese Yen to USD*/
cout << "\n\nThe amount of " << GetAmt <<" Japanese Yen are equal to " << USrate <<" US dollars.\n\n";
cout << "Please enter another selection or enter 6 to exit.\n\n";
cin >> GetNum;

while (GetNum > 6) /* while statement to ensure no number > 6 is inputted*/
{
cout << "\n\nError! Please enter a number from 1 to 6. \n\n";
cin >> GetNum;
}
break;

}/* End of switch*/

} /* End of while loop*/

/* Exit message of program*/

cout << "\n\nThank you for use the Currency Conversion Program.\n\n";
cout << "\n\nPlease press any key to exit.\n\n";
cin >> GetNum;

return 0;

}



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.