/
*currency_conversion_switch.cpp
53 lines (51 loc) · 1.93 KB
/
*currency_conversion_switch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
using namespace std;
int main() {
constexpr double yen {111.7};
constexpr double eur {0.89};
constexpr double pound {0.77};
constexpr double rub {65.36};
constexpr double yuan {6.72};
cout << "Please, enter a lenght followed by a unit (y, e, p) separated by a space." << endl
<< "y - yen" << endl
<< "e - euro" << endl
<< "p - pound" << endl
<< "r - rubles" << endl
<< "c - yuan" << endl //using 'c' (CNY) to prevent errors in swith-statement (similarly cases)
<< "For example: 184 p" << endl;
double length;
char unit;
cin >> length >> unit;
switch (unit)
{
case 'y':
cout << "In " << length << " yen " << length / yen << " dollars." << endl;
break;
case 'e':
if (length == 1)
cout << "In " << length << " euro " << length / eur << " dollars." << endl;
else
cout << "In " << length << " euros " << length / eur << " dollars." << endl;
break;
case 'p':
if (length == 1)
cout << "In " << length << " pound " << length / pound << " dollars." << endl;
else
cout << "In " << length << " pounds " << length / pound << " dollars." << endl;
break;
case 'r':
if (length == 1)
cout << "In " << length << " ruble " << length / rub << " dollars." << endl;
else
cout << "In " << length << " rubles " << length / rub << " dollars." << endl;
break;
case 'c':
cout << "In " << length << " yuan " << length / yuan << " dollars." << endl;
break;
default:
cout << "Sorry, but this currency is not supported";
break;
}
system("pause");
return 0;
}