Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- double getDollarAmt();
- void displayCurrencies();
- char getCurrencySelection();
- bool isSelectionValid(char choice);
- double calcExchangeAmt(double dollars, char choice);
- void displayResults(double dollars, double exchangedAmt, char choice);
- int main()
- {
- double dollars;
- char choice;
- double exchangedAmt;
- dollars = getDollarAmt();
- displayCurrencies();
- choice = getCurrencySelection();
- exchangedAmt = calcExchangeAmt(dollars, choice);
- displayResults(dollars, exchangedAmt, choice);
- system("pause");
- return 0;
- }
- double getDollarAmt()
- {
- double dollars;
- cout << "Enter the total dollar amount you would like to exchange: \n$";
- cin >> dollars;
- return dollars;
- }
- void displayCurrencies()
- {
- cout << "Please select a target currency:\n\n"
- << "A.\t Russian Ruble\n"
- << "B.\t North Korean Won\n"
- << "C.\t Chinese Yuan\n"
- << "D.\t Cuban Peso\n"
- << "E.\t Ethiopian Birr\n"
- << "F.\t Thai Baht\n"
- << "G.\t Canadian Dollars\n"
- << "H.\t Tunisian Dollars\n"
- << "I.\t Egyptian Pound\n";
- }
- char getCurrencySelection()
- {
- bool validChoice = true;
- char choice;
- cout << "\nPlease enter your selection: ";
- cin >> choice;
- // isSelectionValid(choice);
- return validChoice = isSelectionValid(choice);
- }
- bool isSelectionValid(char choice)
- {
- if (choice >= 'A' && choice <= 'I' || choice >= 'a' && choice <= 'z')
- {
- return true;
- }
- else
- {
- cout << "Invalid input.\n";
- return false;
- }
- }
- double calcExchangeAmt(double dollars, char choice)
- {
- double exchangedAmt;
- const double russianRuble = 31.168;
- const double koreanWon = 135.0;
- const double chineseYuan = 6.832;
- const double canadianDollar = 1.1137;
- const double cubanPeso = 1.0;
- const double ethiopianBirr = 9.09;
- const double egyptianPound = 5.6275;
- const double tunisianDinar = 1.3585;
- const double thaiBaht = 34.4;
- switch (toupper(choice))
- {
- case 'A': exchangedAmt = dollars * russianRuble;
- break;
- case 'B': exchangedAmt = dollars * koreanWon;
- break;
- case 'C': exchangedAmt = dollars * chineseYuan;
- break;
- case 'D': exchangedAmt = dollars * canadianDollar;
- break;
- case 'E': exchangedAmt = dollars * cubanPeso;
- break;
- case 'F': exchangedAmt = dollars * ethiopianBirr;
- break;
- case 'G': exchangedAmt = dollars * egyptianPound;
- break;
- case 'H': exchangedAmt = dollars * tunisianDinar;
- break;
- case 'I': exchangedAmt = dollars * thaiBaht;
- break;
- }
- return exchangedAmt;
- }
- void displayResults(double dollars, double exchangedAmt, char choice)
- {
- cout << "$" << dollars << " is " << exchangedAmt;
- switch (toupper(choice))
- {
- case 'A': cout << " Russian Rubles.\n";
- break;
- case 'B': cout << " North Korean Won.\n";
- break;
- case 'C': cout << " Chinese Yuan.\n";
- break;
- case 'D': cout << " Canadian Dollar.\n";
- break;
- case 'E': cout << " Cuban Peso.\n";
- break;
- case 'F': cout << " Ethiopian Birr.\n";
- break;
- case 'G': cout << " Egyptian Pound.\n";
- break;
- case 'H': cout << " Tunisian Dinar.\n";
- break;
- case 'I': cout << " Thai Baht.\n";
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement