# currency conversion using switch

Bjarne Stroustrup “Programming Principles and Practice Using C++”
Using std_lib_facilities.h by Bjarne Stroustrup.

Code:

``````// Philipp Siedler
// Bjarne Stroustrup's PP

#include "std_lib_facilities.h"

int main()
{
const double yenToDollar = 101.10;
const double euroToDollar = 0.89;
const double poundToDollar = 0.76;
const double yuanToDollar = 6.63;
const double kronarToDollar = 8.44;

double dollar = 1;
char currency = 'a';

cout& lt; &lt; "Please enter an amount of dollar(s) you want to convert,\nfollowed by the desired conversion currency (yen = y, euro = e, pound = p, yuan = yu, kronar = k): \n"; cin& gt; &gt; dollar& gt; &gt; currency;

switch (currency)
{
case 'y':
if (dollar* yenToDollar& lt; = 1)
{
cout& lt; &lt; dollar& lt; &lt; " dollar is " & lt; &lt; dollar* yenToDollar& lt; &lt; " yen";
}
else
{
cout& lt; &lt; dollar& lt; &lt; " dollars are " & lt; &lt; dollar* yenToDollar& lt; &lt; " yen\n";
}
break;
case 'e':
if (dollar* euroToDollar& lt; = 1)
{
cout& lt; &lt; dollar& lt; &lt; " dollar is " & lt; &lt; dollar* euroToDollar& lt; &lt; " euro\n";
}
else
{
cout& lt; &lt; dollar& lt; &lt; " dollars are " & lt; &lt; dollar* euroToDollar& lt; &lt; " euros\n";
}
break;
case 'p':
if (dollar* poundToDollar& lt; = 1)
{
cout& lt; &lt; dollar& lt; &lt; " dollar is " & lt; &lt; dollar* poundToDollar& lt; &lt; " pound\n";
}
else
{
cout& lt; &lt; dollar& lt; &lt; " dollars are " & lt; &lt; dollar* poundToDollar& lt; &lt; " pounds\n";
}
break;
case 'yu':
if (dollar* yuanToDollar& lt; = 1)
{
cout& lt; &lt; dollar& lt; &lt; " dollar is " & lt; &lt; dollar* yuanToDollar& lt; &lt; " yuan\n";
}
else
{
cout& lt; &lt; dollar& lt; &lt; " dollars are " & lt; &lt; dollar* yuanToDollar& lt; &lt; " yuans\n";
}
break;
case 'k':
if (dollar* kronarToDollar& lt; = 1)
{
cout& lt; &lt; dollar& lt; &lt; " dollar is " & lt; &lt; dollar* kronarToDollar& lt; &lt; " kronar\n";
}
else
{
cout& lt; &lt; dollar& lt; &lt; " dollars are " & lt; &lt; dollar* kronarToDollar& lt; &lt; " kronars\n";
}
break;
default:
cout& lt; &lt; "I dont know what " & lt; &lt; currency& lt; &lt; " for an currency is\n";
break;
}

keep_window_open();
}``````

Output:

```Please enter an amount of dollar(s) you want to convert,
followed by the desired conversion currency (yen = y, euro = e, pound = p, yuan = yu, kronar = k):
130 p
130 dollars are 98.8 pounds
Please enter a character to exit```