I've been attempting to create a working program that converts other forms of global currencies (such as yen, kroner and pound) to US dollars. I've tried setting up the currency values (converted to US dollar), with reference to the economic exchange rates on Google. The program makes use of constexprs to initialize the numerical values that correspond to the different currencies, as well as chars to represent the different currencies for conversion using a switch statement. However, I haven't been able to get it to work as intended.
Upon runtime, after the project build is compiled, any values automatically refer to the "default:" segment of the switch statement. Any help as to how I would be able to get this to work correctly is appreciated.
My includes come from the standard C++ library headers, whereby the main header includes: #include iostream #include fstream #include sstream #include cmath #include cstdlib #include string #include list #include vector #include algorithm #include stdexcept
Here is my code:
int main()
{
constexpr double yuan_to_dollar = 0.15; // conversion to USD -- values cannot be modified at runtime
constexpr double kroner_to_dollar = 0.15;
constexpr double pound_to_dollar = 1.42;
char currency;
char yuan = 'a';
char kroner = 'b';
char pound = 'c';
double amount = 1;
cout << "Please enter an integer amount in currency: \n";
cin >> currency >> amount >> yuan >> kroner >> pound; // inputs currency double values
switch (currency) {
case 'a':
cout << yuan << "is == " << yuan_to_dollar * 'a' * amount << "currency \n";
case 'b':
cout << kroner << "is == " << kroner_to_dollar * 'b' * amount << "currency \n";
case 'c':
cout << pound << "is == " << pound_to_dollar * 'c' * amount << "currency \n";
default:
cout << "Sorry, I could not determine a suitable form of: " << currency << "currency \n";
}
return 0;
}