aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChanin Timbal <[email protected]>2024-04-17 20:59:24 -0700
committerChanin Timbal <[email protected]>2024-04-17 20:59:24 -0700
commita9a73811c3e14be463034825d696f615ceee6190 (patch)
tree5a4cf3aaf3f99248b603358e2569904d6e754187
parentI committed and pushed this branch (diff)
downloadhomework-1-chaninnohea-feature/unit_tests.tar.xz
homework-1-chaninnohea-feature/unit_tests.zip
currency exchangerfeature/unit_tests
-rw-r--r--CST 126/Homework 1/main.cpp70
1 files changed, 63 insertions, 7 deletions
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp
index 21f25f8..21fcff0 100644
--- a/CST 126/Homework 1/main.cpp
+++ b/CST 126/Homework 1/main.cpp
@@ -10,6 +10,10 @@
using std::cout;
using std::cin;
+float convert(int input, int output, int amount);
+void currency_menu();
+
+
int main()
{
int input_choice = 0;
@@ -20,27 +24,79 @@ int main()
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(input, output, amount)
+float convert(int input, int output, int amount)
{
- const float GBP = 0.80;
- const float Euro = 0.94;
- const float Yen = 152.22;
- const float AUD = 1.55;
- const float USD = 1;
+ 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
+ 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()