blob: 21fcff04b056c8cba4b5b0307aa9e89eedf431d1 (
plain) (
blame)
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
|
// Name: Chanin Timbal
// Class: CST 126
// Date: 04/08/2024
// Assignment: Homework
#include <iostream>
#include <bitset>
#include <cctype>
#include <cstring>
using std::cout;
using std::cin;
float convert(int input, int output, int amount);
void currency_menu();
int main()
{
int input_choice = 0;
int output_choice = 0;
float conversion = 0.0;
float amount = 0.0;
cout << "Choose your input currency: ";
currency_menu();
cin >> input_choice;
cin.ignore(100,'\n');
cout << "";
cout << "choose your output currency: ";
currency_menu();
cin >> output_choice;
cin.ignore(100, '\n');
conversion = convert(input_choice, output_choice, amount);
cout << conversion;
return 0;
}
float convert(int input, int output, int amount)
{
float converted_amount = 0.0;
struct currencies
{
const float GBP = 0.80;
const float Euro = 0.94;
const float Yen = 152.22;
const float AUD = 1.55;
const float USD = 1;
};
currencies currency;
if (input == output)
{
return amount;
}
if (input == 1)
{
input = currency.GBP;
}
else if (input == 2)
{
input = currency.Euro;
}
else if (input == 3)
{
input = currency.Yen;
}
else if (input == 4)
{
input = currency.AUD;
}
else if (input == 5)
{
input = currency.USD;
}
if (output == 1)
{
output = currency.GBP;
}
else if (output == 2)
{
output = currency.Euro;
}
else if (output == 3)
{
output = currency.Yen;
}
else if (output == 4)
{
output = currency.AUD;
}
else if (output == 5)
{
output = currency.USD;
}
converted_amount = static_cast<float>(output) / input * amount;
return converted_amount;
}
void currency_menu()
{
cout << "1. GBP"
<< "2. Euro"
<< "3. Yen"
<< "4. AUD"
<< "5. USD\n";
}
|