aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/currency.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'CST 126/Homework 1/currency.hpp')
-rw-r--r--CST 126/Homework 1/currency.hpp183
1 files changed, 183 insertions, 0 deletions
diff --git a/CST 126/Homework 1/currency.hpp b/CST 126/Homework 1/currency.hpp
new file mode 100644
index 0000000..50bf14e
--- /dev/null
+++ b/CST 126/Homework 1/currency.hpp
@@ -0,0 +1,183 @@
+#ifndef CURRENCY_H
+#define CURRENCY_H
+
+#include <iostream>
+#include <iomanip>
+#include "clear.hpp"
+
+using std::cout;
+using std::cin;
+using std::endl;
+using std::fixed;
+using std::setprecision;
+
+inline void ConvertOther(int convertTo, double &value) {
+
+ switch (convertTo)
+ {
+ case 2:
+ value = value * 1.377;
+ break;
+ case 3:
+ value = value * .9398;
+ break;
+ case 4:
+ value = value * .8032;
+ break;
+ case 5:
+ value = value * 83.61;
+ break;
+ case 6:
+ value = value * 1.547;
+ break;
+ case 7:
+ value = value * .9144;
+ break;
+ default:
+ break;
+ }
+
+}
+
+inline void ConvertUSD(int original, double &value) {
+
+ switch (original)
+ {
+ case 2:
+ value = value / 1.377;
+ break;
+ case 3:
+ value = value / .9398;
+ break;
+ case 4:
+ value = value / .8032;
+ break;
+ case 5:
+ value = value / 83.61;
+ break;
+ case 6:
+ value = value / 1.547;
+ break;
+ case 7:
+ value = value / .9144;
+ break;
+ default:
+ break;
+ }
+}
+
+inline void CurrencyName(int convertTo) {
+
+ switch (convertTo)
+ {
+ case 1:
+ cout << "USD";
+ break;
+ case 2:
+ cout << "CAD";
+ break;
+ case 3:
+ cout << "EUR";
+ break;
+ case 4:
+ cout << "GBP";
+ break;
+ case 5:
+ cout << "INR";
+ break;
+ case 6:
+ cout << "AUD";
+ break;
+ case 7:
+ cout << "CHF";
+ break;
+ default:
+ break;
+ }
+}
+
+inline void Convert(int original, int convertTo, double &value) {
+
+ ConvertUSD(original, value);
+ ConvertOther(convertTo,value);
+
+}
+
+inline int ValidateInput(int input) {
+
+ cin >> input;
+
+ while (input < 1 || input > 8)
+ {
+ cout << "\nInvalid Option, please pick again: ";
+ cin >> input;
+ }
+
+ return input;
+}
+
+inline void Input (int &original, int &convertTo, double &value)
+{
+ cout << "*********************************************************************" << endl;
+ cout << "1. USD\n2. CAD\n3. EUR\n4. GBP\n5. INR\n6. AUD\n7.CHF\n";
+ cout << "Pick the number of the input currency: ";
+ original = ValidateInput(original);
+ cout << "\nWhat is the value of this currency to two decimal places: ";
+ cin >> value;
+ cout << "\nPick the number of the currency to convert to: ";
+ convertTo = ValidateInput(convertTo);
+}
+
+inline void PickCurrency() {
+
+ int original = 0;
+ double value = 0;
+ int convertTo = 0;
+
+ ClearScreen();
+
+ Input(original, convertTo, value);
+
+ if (original != convertTo)
+ Convert(original, convertTo, value);
+
+ ClearScreen();
+
+ cout << "The converted value is " << fixed << setprecision(2) << value << " in ";
+ CurrencyName(convertTo);
+ cout << "." << endl;
+
+ WaitEnter();
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif \ No newline at end of file