#ifndef CURRENCY_H #define CURRENCY_H #include #include #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 > 7) { cout << "\nInvalid Option, please pick again: "; cin >> input; } return input; } inline void Input (int &original, int &convertTo, double &value) { cout << "*********************************************************************\n"; 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 bool ConvertMore() { char again; cout << "\nWould you like to convert more currency? (Y/N): "; cin >> again; if (again == 'Y') return true; else return false; } 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 << ".\n"; if (ConvertMore() == true) PickCurrency(); } #endif