// // convert5.cpp // CSC 215 // John Rogers // // This program converts from either Mexican Pesos or Canadian // dollars to American dollars. It checks its input to make // certain that a legal value for the type of currency is // entered. It allows the user to repeat the conversions // any number of times. // #include #include #include double convert(char currencyType, double amount); int main() { double amount, USDollars; char currencyType; char answer; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); do { cout << "Enter M to convert from Mexican Pesos and C to "; cout << "convert from Canadian dollars: "; cin >> currencyType; cout << "Enter the amount to convert: "; cin >> amount; USDollars = convert(currencyType, amount); cout << "That amount in US dollars is: $" << USDollars << endl; cout << "Do you wish to repeat? "; cin >> answer; answer = toupper(answer); } while (answer == 'Y'); return 0; } double convert(char currencyType, double amount) { double exchangeRate, USDollars; if (currencyType == 'M' || currencyType == 'm') { exchangeRate = 7.60; } else if (currencyType == 'C' || currencyType == 'c') { exchangeRate = 1.48; } else { cout << "The currency type must be either M or C." << endl; exit(1); } USDollars = amount / exchangeRate; return USDollars; }