Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. double getDollarAmt();
  6. void displayCurrencies();
  7. char getCurrencySelection();
  8. bool isSelectionValid(char choice);
  9. double calcExchangeAmt(double dollars, char choice);
  10. void displayResults(double dollars, double exchangedAmt, char choice);
  11. int main()
  12. {
  13.     double dollars;
  14.     char choice;
  15.     double exchangedAmt;
  16.  
  17.     dollars = getDollarAmt();
  18.  
  19.     displayCurrencies();
  20.  
  21.     choice = getCurrencySelection();
  22.  
  23.     exchangedAmt = calcExchangeAmt(dollars, choice);
  24.  
  25.     displayResults(dollars, exchangedAmt, choice);
  26.  
  27.     system("pause");
  28.     return 0;
  29. }
  30. double getDollarAmt()
  31. {
  32.     double dollars;
  33.  
  34.     cout << "Enter the total dollar amount you would like to exchange: \n$";
  35.     cin >> dollars;
  36.  
  37.     return dollars;
  38. }
  39. void displayCurrencies()
  40. {
  41.     cout << "Please select a target currency:\n\n"
  42.         << "A.\t Russian Ruble\n"
  43.         << "B.\t North Korean Won\n"
  44.         << "C.\t Chinese Yuan\n"
  45.         << "D.\t Cuban Peso\n"
  46.         << "E.\t Ethiopian Birr\n"
  47.         << "F.\t Thai Baht\n"
  48.         << "G.\t Canadian Dollars\n"
  49.         << "H.\t Tunisian Dollars\n"
  50.         << "I.\t Egyptian Pound\n";
  51. }
  52. char getCurrencySelection()
  53. {
  54.     bool validChoice = true;
  55.     char choice;
  56.  
  57.     cout << "\nPlease enter your selection:  ";
  58.     cin >> choice;
  59.  
  60. //  isSelectionValid(choice);
  61.  
  62.     return validChoice = isSelectionValid(choice);
  63.  
  64. }
  65. bool isSelectionValid(char choice)
  66. {
  67.     if (choice >= 'A' && choice <= 'I' || choice >= 'a' && choice <= 'z')
  68.     {
  69.         return true;
  70.     }
  71.     else
  72.     {
  73.         cout << "Invalid input.\n";
  74.         return false;
  75.     }
  76. }
  77. double calcExchangeAmt(double dollars, char choice)
  78. {
  79.     double exchangedAmt;
  80.     const double russianRuble = 31.168;
  81.     const double koreanWon = 135.0;
  82.     const double chineseYuan = 6.832;
  83.     const double canadianDollar = 1.1137;
  84.     const double cubanPeso = 1.0;
  85.     const double ethiopianBirr = 9.09;
  86.     const double egyptianPound = 5.6275;
  87.     const double tunisianDinar = 1.3585;
  88.     const double thaiBaht = 34.4;
  89.  
  90.     switch (toupper(choice))
  91.     {
  92.     case 'A': exchangedAmt = dollars * russianRuble;
  93.         break;
  94.     case 'B': exchangedAmt = dollars * koreanWon;
  95.         break;
  96.     case 'C': exchangedAmt = dollars * chineseYuan;
  97.         break;
  98.     case 'D': exchangedAmt = dollars * canadianDollar;
  99.         break;
  100.     case 'E': exchangedAmt = dollars * cubanPeso;
  101.         break;
  102.     case 'F': exchangedAmt = dollars * ethiopianBirr;
  103.         break;
  104.     case 'G': exchangedAmt = dollars * egyptianPound;
  105.         break;
  106.     case 'H': exchangedAmt = dollars * tunisianDinar;
  107.         break;
  108.     case 'I': exchangedAmt = dollars * thaiBaht;
  109.         break;
  110.     }
  111.     return exchangedAmt;
  112. }
  113. void displayResults(double dollars, double exchangedAmt, char choice)
  114. {
  115.     cout << "$" << dollars << " is " << exchangedAmt;
  116.  
  117.         switch (toupper(choice))
  118.         {
  119.         case 'A': cout << " Russian Rubles.\n";
  120.             break;
  121.         case 'B': cout << " North Korean Won.\n";
  122.             break;
  123.         case 'C': cout << " Chinese Yuan.\n";
  124.             break;
  125.         case 'D': cout << " Canadian Dollar.\n";
  126.             break;
  127.         case 'E': cout << " Cuban Peso.\n";
  128.             break;
  129.         case 'F': cout << " Ethiopian Birr.\n";
  130.             break;
  131.         case 'G': cout << " Egyptian Pound.\n";
  132.             break;
  133.         case 'H': cout << " Tunisian Dinar.\n";
  134.             break;
  135.         case 'I': cout << " Thai Baht.\n";
  136.             break;
  137.         }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement