1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
|
/* Attached: Currency Exchange Project, header file: prototypes.h
* =============================================================================
* File: Currency Exchange Project,
* =============================================================================
* Author: gears
* =============================================================================
* Description: Allows the user to enter an amount in U.S dollars. The program
* then presents a menu of foreign currencies from which to select an exchange.
* When the user makes a currency selection, the program displays the U.S dollar
* amount the user entered in the target currency.
* =============================================================================
* Created on May 13, 2014, 6:44 PM
*/
#include <cstdlib>
#include <iostream>
#include <string>
const float RUSSIAN_RUBLE = 31.168;
const float NORTH_KOREAN_WON = 135.00; /* variables which hold global constants */
const float CHINESE_YUAN = 6.832;
const float CANADIAN_DOLLAR = 1.1137;
const float CUBAN_PESO = 1.0;
const float ETHIOPIAN_BIRR = 9.09;
const float EGYPTIAN_POUND = 5.6275;
const float TUNISIAN_DINAR = 1.3585;
const float THAI_BAHT = 34.4;
float getDollarAmount();
void DisplayCurrencies();
char GetcurrencySelection();
bool IsSelectionValid( char test);
float CalcExchangeAmount (char selection, float DollarAmount);
void DisplayResults(float DollarAmount, float Exchange, string Nameofcountry);
using namespace std;
/* ==main=======================================================================
*
* =============================================================================
*/
int main(int argc, char** argv)
{
char selection;
float DollarAmount; // variables, it will hold values for the program
char choice;
float Exchange;
string Nameofcountry;
float Amount;
do
{ // clears the screen when the loop restarts
system ("cls");
// it is a function call and gets the results from dollar maount
DollarAmount = getDollarAmount();
// this is a function call, it displays the currencies for the user
DisplayCurrencies();
// function call, retrieves the selection from the user
choice = GetcurrencySelection();
// gets the user input and assigns the input to the variable "choice"
switch(toupper(choice))
{
case 'A': Nameofcountry = "Russian Rubles";
break;
case 'B': Nameofcountry = "North Korean Won";
break;
case 'C': Nameofcountry = "Chinese Yuan";
break;
case 'D': Nameofcountry = "Canadian Dollars";
break;
case 'E': Nameofcountry = "Cuban Pesos";
break;
case 'F': Nameofcountry = "Ethiopian Birr";
break;
case 'G': Nameofcountry = "Egyptian Pounds";
break;
case 'H': Nameofcountry = "Tunisian Dinars";
break;
case 'I': Nameofcountry = "Thai Baht";
break;
}
// Function call, the variable "Amount"
//accepts the calculation of "CalcExchangeAmount"
Amount = CalcExchangeAmount (choice, DollarAmount);
// function call, displays the results from each given variable
// in the arguement
DisplayResults(DollarAmount,Exchange,Nameofcountry);
cout << " would you like to restart and try again? (Y/N)"<< endl;
cin >> choice;
} while(toupper(choice)=='Y');
return 0;
}
//== getDollarAmoun ============================================================
// this function retrieves the users amount and it is then accepted into the
// variable amount. it is then returned back to main where the value is held in
// " DollarAmount"
//
//Precondition:
// Not available
//Post-condition:
// the value is returned to main and the variable "DollarAmount" then is
// responsible for holding that value.
//==============================================================================
float getDollarAmount()
{
float Amount;
cout << "enter the amount please to exchange";
cin >> Amount;
return Amount;
}// end of getDollarAmount()
//==============================================================================
//
void DisplayCurrencies()
{
cout << "choose one good sir or ma'am"<< endl;
cout << "A Russian Ruble\n";
cout << "B North Korean Won\n";
cout << "C Chinese Yuan\n";
cout << "D Cuban Peso\n";
cout << "E Ethiopian Birr\n";
cout << "F Thai Baht\n";
cout << "G Canadian Dollars\n";
cout << "H Tunisian Dinar\n";
cout << "I Egyptian Pound\n";
}
char GetcurrencySelection()
{
char selection;
cout << "enter your selection: ";
cin >> selection;
while(!(IsSelectionValid(selection)))
{
cout << "error please try again. Please make a selection";
cin >> selection;
}
return selection;
}
bool IsSelectionValid( char selection)
{
bool test;
if (toupper(test) >= 'A' && toupper (test) <= 'J')
{
test = true;
}
else {
test = false;
}
return test;
}
float CalcExchangeAmount (char choice, float DollarAmount)
{
float amount;
switch (toupper(choice))
{
case'A': amount = RUSSIAN_RUBLE * DollarAmount;
break;
case 'B': amount = NORTH_KOREAN_WON * DollarAmount;
break;
case 'C': amount = CHINESE_YUAN * DollarAmount;
break;
case 'D': amount = CANADIAN_DOLLAR * DollarAmount;
break;
case 'E': amount = CUBAN_PESO * DollarAmount;
break;
case 'F': amount = ETHIOPIAN_BIRR * DollarAmount;
break;
case 'G': amount = EGYPTIAN_POUND * DollarAmount;
break;
case 'H': amount = TUNISIAN_DINAR * DollarAmount;
break;
case 'I': amount = THAI_BAHT * DollarAmount;
}
return amount;
}
void DisplayResults(float DollarAmount, float Exchange,string Nameofcountry)
{
cout << "\n$ " << fixed << setprecision(2)<< DollarAmount
<< " is " << fixed << setprecision(2) << Exchange
<< " " << Nameofcountry << "." << endl;
}
|