Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct currency {
- string currencyCode;
- double converison;
- };
- void printCurrencies(currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[]);
- string convertingToday(string &toBeConverted);
- string convertTo(string &convertingTo);
- void confirmConversion(string convertingTo, string toBeConverted );
- double convertCurrencies(string convertingTo, string toBeConverted, double amount, double &finalResult, currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[] );
- double enterValues(string toBeConverted, double &amount);
- currency records;
- currency canadianRecords[4] = {{ "CAN - GBP:", 0.57}, {"CAN - USD:", 0.74}, {"CAN - ERO:", 0.67}, {"CAN - BIT:", 0.00031}};
- currency bitcoinRecords[4] = {{"BIT - GBP:", 1842.56}, {"BIT - USD:", 2386.12}, {"BIT - ERO:", 2133.80}, {"BIT - CAN:", 3207.06}};
- currency euroRecords[4] = {{"ERO - GBP:", 0.86}, {"ERO - USD:", 0.89}, {"ERO - BIT:", 0.00057}, {"ERO - CAN:", 1.50}};
- currency usRecords[4] = {{"USD - GBP:", 0.77}, {"USD - ERO:", 0.89}, {"USD - BIT:", 0.00042}, {"USD - CAN:", 1.34}};
- currency poundRecords[4] = {{"GBP - USD:", 1.29},{"GBP - ERO:", 1.16},{"GBP - BIT:", 0.00054}, {"GBP - CAN:", 1.74}};
- int main() {
- string toBeConverted = "ERROR";
- string convertingTo = "ERROR";
- double amount;
- double finalResult;
- convertingToday(toBeConverted);
- convertTo(convertingTo);
- confirmConversion(convertingTo, toBeConverted);
- enterValues(toBeConverted, amount);
- convertCurrencies(convertingTo, toBeConverted, amount, finalResult, &records, canadianRecords, bitcoinRecords, euroRecords, usRecords, poundRecords);
- cout << amount << " to " << setprecision(6) << finalResult;
- return 0;
- };
- double enterValues(string toBeConverted, double &amount ){
- cout << "Enter the amount of " << toBeConverted << " you would like to change: " << endl;
- cin >> amount;
- return amount;
- }
- double convertCurrencies(string convertingTo, string toBeConverted, double amount, double &finalResult, currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundrecords[] ){
- string conversionCode = toBeConverted + " - " + convertingTo;
- double conversionMult;
- for(int i(0); i <= 4; ++i){
- if(canadianRecords[i].currencyCode == conversionCode){
- conversionMult = canadianRecords[i].converison;
- }
- }
- for(int i(0); i <= 4; ++i){
- if(bitcoinRecords[i].currencyCode == conversionCode){
- conversionMult = bitcoinRecords[i].converison;
- }
- }
- for(int i(0); i <= 4; ++i){
- if(euroRecords[i].currencyCode == conversionCode){
- conversionMult = euroRecords[i].converison;
- }
- }
- for(int i(0); i <= 4; ++i){
- if(usRecords[i].currencyCode == conversionCode){
- conversionMult = usRecords[i].converison;
- }
- }
- for(int i(0); i <= 4; ++i){
- if(poundRecords[i].currencyCode == conversionCode){
- conversionMult = poundRecords[i].converison;
- }
- }
- cout << "MULT IS: " << conversionMult;
- finalResult = amount * conversionMult;
- return finalResult;
- }
- void confirmConversion(string convertingTo, string toBeConverted ){
- string startOver;
- cout << "You are converting " << toBeConverted << " to " << convertingTo << "." << endl << "Is this correct? (Enter Y to confirm, N to start over:" << endl;
- cin >> startOver;
- if(startOver == "Y"){
- return;
- }
- else {
- convertingToday(toBeConverted);
- }
- }
- void printCurrencies(currency *records, currency canadianRecords[], currency bitcoinRecords[], currency euroRecords[], currency usRecords[], currency poundRecords[]){
- cout << "We can convert between the following:" << endl;
- cout << "Canadian converisons:" << endl;
- for(int i(0); i <= 4; ++i){
- cout << canadianRecords[i].currencyCode;
- cout << endl;
- }
- cout << endl;
- cout << "Bitcoin conversions:" << endl;
- for(int i(0); i <= 4; ++i){
- cout << bitcoinRecords[i].currencyCode;
- cout << endl;
- }
- cout << endl;
- cout << "Euro conversions:" << endl;
- for(int i(0); i <= 4; ++i){
- cout << euroRecords[i].currencyCode;
- cout << endl;
- }
- cout << endl;
- cout << "US Dollar conversions:" << endl;
- for(int i(0); i <= 4; ++i){
- cout << usRecords[i].currencyCode;
- cout << endl;
- }
- cout << endl;
- cout << "British Pound conversions:" << endl;
- for(int i(0); i <= 4; ++i){
- cout << poundRecords[i].currencyCode;
- cout << endl;
- }
- cout << endl;
- }
- string convertingToday(string &toBeConverted){
- string startOver;
- string seeAll;
- /*cout << "What currency are you converting from today?" << endl;
- cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
- cin >> toBeConverted;
- if(toBeConverted != "GBP" || "USD" || "CAN" || "BIT" || "ERO"){
- cout << "Looks like you entered the currency code wrong, pick again:" << endl;
- cin >> toBeConverted;
- }
- cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
- cout << "Enter Y to continue or N to pick again:" << endl;
- cin >> startOver;
- while(startOver != "Y"){
- cout << "What currency are you converting from today?" << endl;
- cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
- cin >> toBeConverted;
- }
- if(toBeConverted != "GBP" || "USD" || "CAN" || "BIT" || "ERO"){
- cout << "Looks like you entered the currency code wrong, pick again:" << endl;
- cin >> toBeConverted;
- }
- cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
- cout << "Enter Y to continue or N to pick again:" << endl;
- cin >> startOver;*/
- while(startOver != "Y"){
- cout << "What currency are you converting from today?" << endl;
- cout << "You can convert between:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
- cin >> toBeConverted;
- while(toBeConverted != "GBP" && toBeConverted !="USD" && toBeConverted !="CAN" && toBeConverted !="BIT" && toBeConverted !="ERO"){
- cout << "Looks like you entered the currency code wrong, pick again:" << endl;
- cin >> toBeConverted;
- }
- cout << "To Confirm, you want to convert " << toBeConverted << " today?" << endl;
- cout << "Enter Y to continue or N to pick again:" << endl;
- cin >> startOver;
- }
- return toBeConverted;
- }
- string convertTo(string &convertingTo){
- string startOver;
- string seeAll;
- while(startOver != "Y"){
- cout << "What currency are you converting to?" << endl;
- cout << "You can convert to:" << endl << "GBP" << endl << "CAN" << endl << "BIT" << endl << "USD" << endl << "ERO" << endl;
- cin >> convertingTo;
- while(convertingTo != "GBP" && convertingTo !="USD" && convertingTo !="CAN" && convertingTo !="BIT" && convertingTo !="ERO"){
- cout << "Looks like you entered the currency code wrong, pick again:" << endl;
- cin >> convertingTo;
- }
- cout << "To Confirm, you want to convert " << convertingTo << " today?" << endl;
- cout << "Enter Y to continue or N to pick again:" << endl;
- cin >> startOver;
- }
- return convertingTo;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement