diff options
| author | Chanin Timbal <[email protected]> | 2024-05-31 16:59:48 -0700 |
|---|---|---|
| committer | Chanin Timbal <[email protected]> | 2024-05-31 16:59:48 -0700 |
| commit | a9104416ca70a3732affec2aaf4d9fb14963865e (patch) | |
| tree | 8570a6e225265459ddb34b64cc7d578873ecdcf1 /CST 126/Homework 1/main.cpp | |
| parent | Homework 2 first commit (diff) | |
| download | homework-1-chaninnohea-a9104416ca70a3732affec2aaf4d9fb14963865e.tar.xz homework-1-chaninnohea-a9104416ca70a3732affec2aaf4d9fb14963865e.zip | |
Purged all previous commits and reset Repo
Diffstat (limited to 'CST 126/Homework 1/main.cpp')
| -rw-r--r-- | CST 126/Homework 1/main.cpp | 178 |
1 files changed, 0 insertions, 178 deletions
diff --git a/CST 126/Homework 1/main.cpp b/CST 126/Homework 1/main.cpp deleted file mode 100644 index a82ca3b..0000000 --- a/CST 126/Homework 1/main.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Name: Chanin Timbal -// Class: CST 126 -// Date: 04/08/2024 -// Assignment: Homework -// This program converts an amount from one chosen currency into another - -#include <iostream> -#include <cctype> -#include <cstring> -using std::cout; -using std::cin; - -//Protoypes -void display_options(); -float convert(float input, float output, float amount); -void run_conversion(char again); -void currency_menu(); - -//Main to run the program -int main() -{ - int option = 0; - - cout << "Welcome! Please choose an option: \n"; - display_options(); - cin >> option; - cin.ignore(100, '\n'); - - while (option != 0) - { - if (option == 1) - { - char again = 'Y'; - run_conversion(again); - cin >> again; - cin.ignore(100,'\n'); - } - - else if (option == 2) - { - - } - - else if (option == 3) - { - - } - else - { - cout << "That is not one of the options!"; - display_options(); - cin >> option; - cin.ignore(100, '\n'); - } - - display_options(); - cin >> option; - cin.ignore(100, '\n'); - } - - return 0; -} - -//menu options -void display_options() -{ - cout << "1. Currency Converter\n"; - cout << "2. Guessing Game\n"; - cout << "3. Temperature Logger\n"; - cout << "0. Quit\n"; -} - -//Conversion Calculator -float convert(float input, float output, float 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 = output / input * amount; - return converted_amount; -} - -//Loop to run the conversion while the user wants to -void run_conversion(char again) -{ - while (toupper(again) != 'N') - { - 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 << "\nchoose your output currency: "; - cin >> output_choice; - cin.ignore(100, '\n'); - cout << "\nWhat is the amount you would like to convert: "; - cin >> amount; - cin.ignore(100, '\n'); - conversion = convert(input_choice, output_choice, amount); - cout << "In the new currency, that amount is " << conversion << std::endl; - cout << "\nDo you want to use the conversion tool again? (Y/N): "; - cin >> again; - cin.ignore(100, '\n'); - if (toupper(again) != 'Y') - { - cout << "Thank you for using the currency conversion tool! \n"; - } - } -} - -//Menu display -void currency_menu() -{ - cout << "\n\n1. GBP\n"; - cout << "2. Euro\n"; - cout << "3. Yen\n"; - cout << "4. AUD\n"; - cout << "5. USD\n\n"; -}
\ No newline at end of file |