-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrency-coverter.cpp
120 lines (99 loc) · 2.73 KB
/
currency-coverter.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <conio.h>
using namespace std;
class converter {
public:
float inputGBP(float pound);
float inputCNY(float yuan);
float inputPKR(float rupee);
float outputGBP(float dollar);
float outputCNY(float dollar);
float outputPKR(float dollar);
};
float converter::inputPKR(float rupee) {
return (rupee / 250.55);
}
float converter::inputCNY(float yuan) {
return (yuan / 6.78);
}
float converter::inputGBP(float pound) {
return (pound / 0.81);
}
float converter::outputGBP(float dollar) {
return (0.81 * dollar);
}
float converter::outputCNY(float dollar) {
return (6.78 * dollar);
}
float converter::outputPKR(float dollar) {
return (250.55 * dollar);
}
void validation(int &value) {
while (!((value > 0) && (value < 5))) {
cout << "\nPlease enter valid option: ";
cin >> value;
}
}
void validation(double &value) {
while (value < 0) {
cout << "\nPlease enter positive amount: ";
cin >> value;
}
}
int main() {
converter obj;
int choiceFrom, choiceTo;
double amount, dollar;
char user;
do {
cout << "\n--------------------------------------------------CURRENCY CONVERTER--------------------------------------------------";
cout << "\nEnter currency to be converter from(pound 1: dollar 2: yuan 3: rupee 4): ";
cin >> choiceFrom;
validation(choiceFrom);
cout << "\nEnter amount: ";
cin >> amount;
validation(amount);
switch (choiceFrom)
{
case 1:
dollar = obj.inputGBP(amount);
break;
case 2:
dollar = amount;
break;
case 3:
dollar = obj.inputCNY(amount);
break;
case 4:
dollar = obj.inputPKR(amount);
break;
default:
cout << "\nError!";
break;
}
cout << "\nChanged to (pound 1: dollar 2: yuan 3: rupee 4): ";
cin >> choiceTo;
validation(choiceTo);
switch (choiceTo)
{
case 1:
cout << "\nThe amount in pounds is " << obj.outputGBP(dollar);
break;
case 2:
cout << "\nThe amount in dollars is: " << dollar;
break;
case 3:
cout << "\nThe amount in yuan is: " << obj.outputCNY(dollar);
break;
case 4:
cout << "\nThe amount in rupee is: " << obj.outputPKR(dollar);
break;
default:
cout << "\nError!";
break;
}
cout << "\ncout << \"wanna do this again (Y/N)?\" ";
cin >> user;
} while ((user == 'y') || (user == 'Y'));
return 0;
}