/* Lab Assignment #1 Due: October 27, 2011 Messri, Pedram StudentID: 88-159-5802 CS575 - Introduction to C++ */ #include #include #include using namespace std; #define GBP_USD 1.56366 // British Pound #define CAD_USD 0.972763 // Canadian Dollar #define DKK_USD 0.182804 // Danish Krone #define EUR_USD 1.3607 // Euro #define SEK_USD 0.149196 // Swedish Krona #define CHF_USD 1.09911 // Swiss Franc int main(int argc, char *argv[]) { bool repeat = true; int selected_currency; double amount_to_convert = 0.0; double converted_to_usd = 0.0; double total_usd = 0.0; cout << endl; cout << "Currency Converter Program By Pedram Messri" << endl; cout << "Enter the currency to convert:" << endl; cout << "1 British Pound" << endl; cout << "2 Canadian Dollar" << endl; cout << "3 Danish Krone" << endl; cout << "4 Euro" << endl; cout << "5 Swedish Krona" << endl; cout << "6 Swedish Franc" << endl; cout << "-999 Terminate Program" << endl; cout << endl; while(repeat) { converted_to_usd = 0.0; cout << "Currency Selection: "; cin >> selected_currency; cin.ignore(numeric_limits::max(),'\n'); if(cin) { if(selected_currency == -999) { repeat = false; } else if(selected_currency >= 1 && selected_currency <= 6) { cout << "How much do you have? "; cin >> amount_to_convert; cin.ignore(numeric_limits::max(),'\n'); if(cin) { switch(selected_currency) { case 1: //GBP_USD converted_to_usd = amount_to_convert * GBP_USD; total_usd += converted_to_usd; break; case 2: //CAD_USD converted_to_usd = amount_to_convert * CAD_USD; total_usd += converted_to_usd; break; case 3: //DKK_USD converted_to_usd = amount_to_convert * DKK_USD; total_usd += converted_to_usd; break; case 4: //EUR_USD converted_to_usd = amount_to_convert * EUR_USD; total_usd += converted_to_usd; break; case 5: //SEK_USD converted_to_usd = amount_to_convert * SEK_USD; total_usd += converted_to_usd; break; case 6: //CHF_USD converted_to_usd = amount_to_convert * CHF_USD; total_usd += converted_to_usd; break; default: cout << "This is an invalid selection, please try again." << endl; cout << "Valid selections are between 1 through 6, or -999 to terminate." << endl; break; } cout << "That is $" << setprecision(3) << converted_to_usd << endl; } else { cin.clear(); cin.ignore(numeric_limits::max(),'\n'); cout << "That is an invalid decimal amount, please try again." << endl; } } } else { cin.clear(); cin.ignore(numeric_limits::max(),'\n'); cout << "That is an invalid selection, please try again." << endl; cout << "Please only select between 1 through 6, or -999 to terminate." << endl; } } cout << "Your total in US Dollars is $" << setprecision(3) << total_usd << endl; return 0; }