// // convert4.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. // #include #include double convert(char currencyType, double amount); int main() { double amount, USDollars; char currencyType; 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.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); cout << "That amount in US dollars is: $" << USDollars << endl; 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; }