aboutsummaryrefslogtreecommitdiff
path: root/CST 126/Homework 1/currency.hpp
blob: 50bf14e08c0d4de3e721eee29a335a5123857694 (plain) (blame)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#ifndef CURRENCY_H
#define CURRENCY_H

#include <iostream>
#include <iomanip>
#include "clear.hpp"

using std::cout;
using std::cin;
using std::endl;
using std::fixed;
using std::setprecision;

inline void ConvertOther(int convertTo, double &value) {

	switch (convertTo)
	{
	case 2:
		value = value * 1.377;
		break;
	case 3:
		value = value * .9398;
		break;
	case 4:
		value = value * .8032;
		break;
	case 5:
		value = value * 83.61;
		break;
	case 6:
		value = value * 1.547;
		break;
	case 7:
		value = value * .9144;
		break;
	default:
		break;
	}

}

inline void ConvertUSD(int original, double &value) {

	switch (original)
	{
	case 2:
		value = value / 1.377;
		break;
	case 3:
		value = value / .9398;
		break;
	case 4:
		value = value / .8032;
		break;
	case 5:
		value = value / 83.61;
		break;
	case 6:
		value = value / 1.547;
		break;
	case 7:
		value = value / .9144;
		break;
	default:
		break;
	}
}

inline void CurrencyName(int convertTo) {

	switch (convertTo)
	{
	case 1:
		cout << "USD";
		break;
	case 2:
		cout << "CAD";
		break;
	case 3:
		cout << "EUR";
		break;
	case 4:
		cout << "GBP";
		break;
	case 5:
		cout << "INR";
		break;
	case 6:
		cout << "AUD";
		break;
	case 7:
		cout << "CHF";
		break;
	default:
		break;
	}
}

inline void Convert(int original, int convertTo, double &value) {

	ConvertUSD(original, value);
	ConvertOther(convertTo,value);

}

inline int ValidateInput(int input) {

	cin >> input;

	while (input < 1 || input > 8)
	{
		cout << "\nInvalid Option, please pick again: ";
		cin >> input;
	}

	return input;
}

inline void Input (int &original, int &convertTo, double &value)
{
	cout << "*********************************************************************" << endl;
	cout << "1. USD\n2. CAD\n3. EUR\n4. GBP\n5. INR\n6. AUD\n7.CHF\n";
	cout << "Pick the number of the input currency: ";
	original = ValidateInput(original);
	cout << "\nWhat is the value of this currency to two decimal places: ";
	cin >> value;
	cout << "\nPick the number of the currency to convert to: ";
	convertTo = ValidateInput(convertTo);
}

inline void PickCurrency() {

	int original = 0;
	double value = 0;
	int convertTo = 0;

	ClearScreen();

	Input(original, convertTo, value);

	if (original != convertTo)
		Convert(original, convertTo, value);

	ClearScreen();

	cout << "The converted value is " << fixed << setprecision(2) << value << " in ";
	CurrencyName(convertTo);
	cout << "." << endl;

	WaitEnter();

}






























#endif