Converting currency

as the title says, my program converts u.s currency to a foreign countries currency.

for some reason when i run the program and i choose a country, its always displaying Egyptian pound currency instead. no matter what country i select its always calculating the currency to epyptian pound. can someone help me fix this problem?

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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
  * 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>
#include <iomanip>

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, std::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(selection))
        {
            case 'A': Nameofcountry = "Russian Rubles";
            break;
            case 'B': Nameofcountry = "North Korean Won";
            break;
            case 'C': Nameofcountry = "Chinese Yuan";
            break;
            case 'D': Nameofcountry = "Cuban Peso";
            break;
            case 'E': Nameofcountry = "Ethiopian Birr";
            break;
            case 'F': Nameofcountry = "Thai Baht";
            break;
            case 'G': Nameofcountry = "Canadian Dollars";
            break;
            case 'H': Nameofcountry = "Tunisian Dinar";
            break;
            case 'I': Nameofcountry = " Egyptian Pound";
            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,Amount,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 desired U.S currency you wish to exchange please\n";
    cin >> Amount;
    return Amount;
    
}// end of getDollarAmount()
//==============================================================================
////== DisplayCurrencies() =====================================================
// 
// Display the menu for the currencies
// 
//
//Precondition: 
//      not available
//Post-condition:
//      display the selected country
//     
//==============================================================================
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";
}// end of DisplayCurrencies()
// =============================================================================
////== GetcurrencySelection() ==================================================
// function, accepts the selection from user and checks if its valid.
// If it is valid, the "selection" variable would hold that validity. 
// 
//
//Precondition: 
//      
//Post-condition:
//      
//     
//==============================================================================

char GetcurrencySelection()
{
    char selection;
    cout << "enter your selection: \n";
    cin >> selection;
    
    while(!(IsSelectionValid(selection)))
    {
        cout << "error please try again. Please make a selection";
        cin >> selection;
    }
    return selection;
    
}// end of GetcurrencySelection()
// =============================================================================
////==  =====================================================
// 
// 
// 
//
//Precondition: 
//      
//Post-condition:
//      
//     
//==============================================================================
bool IsSelectionValid( char selection)
{
    bool test;
    
    if (toupper(selection) >= 'A' && toupper(selection) <= 'I')
    {
        test = true;
    }
    else {
        test = false;
    }
    return test;
} // end of IsSelectionValid()
// =============================================================================
////==  =====================================================
// 
// 
// 
//
//Precondition: 
//      
//Post-condition:
//      
//     
//==============================================================================
float CalcExchangeAmount (char selection, float DollarAmount)
{
    float amount;
    
    switch (toupper(selection))
    {
        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;
}// end of CalcExchangeAmount()
// =============================================================================
////==  =====================================================
// 
// 
// 
//
//Precondition: 
//      
//Post-condition:
//      
//     
//==============================================================================
void DisplayResults(float DollarAmount, float Amount,string Nameofcountry)
{
    cout << "\n$ " << fixed << setprecision(2)<< DollarAmount 
         << " is " << fixed << setprecision(2) << Amount
         << " "    << Nameofcountry << "." << endl;
}// end of DisplayResults
// ============================= 
line 59 - that switch case should be on choice, not selection

line 210 to 226 - these don't match the order in which you have the currencies in the menu
thank you!!
Topic archived. No new replies allowed.