Bool statement not working, PLEASE HELP!! PROJECT DUE 8/5/15
Aug 5, 2015 at 3:48am UTC
Hey guys i need help on my project. So everything runs smoothly until the user inputs a different answer other than the ones asked for (the choices are a-i). So if the user puts a different answer its suppose to runt he program again. I do not know what I am doing wrong.
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
#include <iostream>
#include <string>
#include <cctype >
using namespace std;
const float RUSSIAN_RUBLE = 31.16840f;
const float NORTH_KOREAN_WON = 135.00f;
const float CHINESE_YUAN = 6.83200f;
const float CANADIAN_DOLLAR = 1.1137f;
const float CUBAN_PESO = 1.00f;
const float ETHIOPIAN_BIRR = 9.09f;
const float EGYPTIAN_POUND = 5.6275f;
const float TUNISIAN_DINAR = 1.3585f;
const float THAI_BAHT = 34.40f;
float getDollarAmt();
void displayCurrencies();
char getCurrencySelection();
float calcExchangeAmt(char letter, float dollar);
void displayResults(float dollar, float sum, char letter);
bool isSelectionValid(char letter);
int main()
{
float dollar;
char letter;
float sum;
char answer = 'Y' ;
while (toupper(answer) == 'Y' )
{
dollar = getDollarAmt();
displayCurrencies();
letter = getCurrencySelection();
calcExchangeAmt(letter, dollar);
sum = calcExchangeAmt(letter, dollar);
displayResults(dollar, sum, letter);
cout << "\nDo you wish to continue (Y for yes - N for no): " ;
cin >> answer;
system("cls" );
}
}
float getDollarAmt()
{
float dollar;
cout << "Please enter the total dollar amount to exchange: $" ;
cin >> dollar;
return dollar;
}
void displayCurrencies()
{
cout << "Please select a target currenc y:" << endl << endl
<< "A Russian Ruble" << endl
<< "B North Korean Won" << endl
<< "C Chinese Yuan" << endl
<< "D Cuban Peso" << endl
<< "E Ethiopian Birr" << endl
<< "F Thai Baht" << endl
<< "G Canadian Dollars" << endl
<< "H Tunisian Dinar" << endl
<< "I Egyptian Pound" << endl << endl;
}
char getCurrencySelection()
{
char letter;
bool letterValid = false ;
while (letterValid == false )
{
cout << "Please enter your selection: " ;
cin >> letter;
letterValid = isSelectionValid(letter);
}
return letter;
}
bool isSelectionValid(char letter)
{
if ((toupper(letter) >= 'A' ) && (toupper(letter) <= ' I' ))
{
return true ;
}
else
{
return false ;
}
}
float calcExchangeAmt(char letter, float dollar)
{
float sum;
switch (toupper(letter))
{
case 'A' : sum = RUSSIAN_RUBLE * dollar;
break ;
case 'B' : sum = NORTH_KOREAN_WON * dollar;
break ;
case 'C' : sum = CHINESE_YUAN * dollar;
break ;
case 'D' : sum = CUBAN_PESO * dollar;
break ;
case 'E' : sum = ETHIOPIAN_BIRR * dollar;
break ;
case 'F' : sum = THAI_BAHT * dollar;
break ;
case 'G' : sum = CANADIAN_DOLLAR * dollar;
break ;
case 'H' : sum = TUNISIAN_DINAR * dollar;
break ;
case ' I' : sum = EGYPTIAN_POUND * dollar;
break ;
}
return sum;
}
void displayResults(float dollar, float sum, char letter)
{
string word;
string word2;
string word3;
switch (toupper(letter))
{
case 'A' : word = "Russian" ;
word2 = "Ruble" ;
break ;
case 'B' : word = "North" ;
word2 = "Korean" ;
word3 = "Won" ;
break ;
case 'C' : word = "Chinese" ;
word2 = "Yuan" ;
break ;
case 'D' : word = "Cuban" ;
word2 = "Peso" ;
break ;
case 'E' : word = "Ethiopian" ;
word2 = "Birr" ;
break ;
case 'F' : word = " Thai" ;
word2 = "Baht" ;
break ;
case 'G' : word = "Canadian" ;
word2 = "Dollars" ;
break ;
case 'H' : word = "Tunisian" ;
word2 = "Dinar" ;
break ;
case ' I' : word = "Egyptian" ;
word2 = "Pound" ;
break ;
}
cout << "$" << dollar << " is " << sum << " " << word << " "
<< word2 << " " << word3;
} // end of displayResults()
Aug 5, 2015 at 4:00am UTC
Last edited on Aug 5, 2015 at 4:00am UTC
Topic archived. No new replies allowed.