C++ -- How can I get a working currency converter using switch-statements and constexprs?
<p>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.</p>

<p>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.</p>

<p>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 </p>

<p>Here is my code:</p>

<pre><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 &lt;&lt; "Please enter an integer amount in currency: \n";

cin &gt;&gt; currency &gt;&gt; amount &gt;&gt; yuan &gt;&gt; kroner &gt;&gt; pound; // inputs currency double values

switch (currency) {

case 'a':
    cout &lt;&lt; yuan &lt;&lt; "is == " &lt;&lt; yuan_to_dollar * 'a' * amount &lt;&lt; "currency \n";

case 'b':
    cout &lt;&lt; kroner &lt;&lt; "is == " &lt;&lt; kroner_to_dollar * 'b' * amount &lt;&lt; "currency \n";

case 'c':
    cout &lt;&lt; pound &lt;&lt; "is == " &lt;&lt; pound_to_dollar * 'c' * amount &lt;&lt; "currency \n";

default:
    cout &lt;&lt; "Sorry, I could not determine a suitable form of: " &lt;&lt; currency &lt;&lt; "currency \n";
}

return 0;
</code></pre>

<p>}</p>