-
Notifications
You must be signed in to change notification settings - Fork 1
/
settingMode.h
343 lines (296 loc) · 7.74 KB
/
settingMode.h
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
// Note: This header file uses functions from QOL and audio headers,
// for an explenation on what these functions do go to the respective header file.
// it is probably a better idea to go to the header files first as the functions there are used here multiple times.
#pragma once // Includes the file only once in a single compilation.
#include <iostream>
#include <string>
#include <limits>
#include <iomanip> // For setw() func.
#include "audio.h"
#include "qualityOfLife.h"
#undef max
// Check line 8 in QOL header fer an explanation to this...
// This are just there to make life easier.
using namespace std;
// Allows the user to change the amount of coffees inside the machines inventory.
void coffeeInvent(int cAmnt[], string cTypes[]) {
short choice, strSize = charCount(cTypes);
int temp;
start:
cls();
cout << "Which type of coffee would you like to change the amount of?" << endl;
for (short i = 0; i < 5; i++) {
cout << (i + 1) << ") " << setw(strSize + 1) << cTypes[i] << ": " << cAmnt[i] << endl;
}
cout << "0) Return." << endl << "~> ";
cin >> choice;
beepBeep();
if (choice == 0) {
cls();
return;
}
if ((choice >= 1) && (choice <= 5)) {
cout << cAmnt[choice - 1] << " ~> ";
cin >> temp;
beepBeep();
if (!isPos(temp)) {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
else { cAmnt[choice - 1] = temp; } // Checks if the Users input is pos, if it is it goes ahead with the change.
goto start;
}
else{
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
}
// Allows the user to change the amount of coins in inventory.
void coinInvent(int coinAmnt[], const long double arrVal[]) {
short choice;
int temp;
start:
cls();
cout << "Which coin amount would you like to change?" << endl;
for (short i = 0; i < 7; i++) {
cout << (i + 1) << ") " << setw(4) << arrVal[i] << ": " << coinAmnt[i] << endl;
}
cout << "0) Return." << endl << "~> ";
cin >> choice;
beepBeep();
if (choice == 0) {
cls();
return;
}
if ((choice >= 1) && (choice <= 7)) {
cout << coinAmnt[choice - 1] << " ~> ";
cin >> temp;
beepBeep();
if (isPos(temp)) {
coinAmnt[choice - 1] = temp;
}
else{
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
}
}
else {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
}
goto start;
}
// Allows for the user to change the price of certain coffees.
void changePrices(double cPrices[], string cTypes[]) {
short choice;
int strSize = charCount(cTypes);
double temp; // This variable is used to store a value temporarily, until the input is verified and then the value is sent to the actual array.
start:
cls();
cout << "Which coffee prices would you like to modify?" << endl;
for (short i = 0; i < 5; i++) {
cout << (i + 1) << ") " << setw(strSize + 1) << cTypes[i] << ": "; print(to_string(cPrices[i]), cPrices[i], digCount(cPrices) - 3); cout << " KM." << endl;
}
cout << "0) Return." << endl << "~> ";
cin >> choice;
beepBeep();
if (choice == 0) {
cls();
return;
}
if ((choice >= 1) && (choice <= 5)) {
cout << cPrices[choice - 1] << "~> ";
cin >> temp;
if (!isDouble(temp)) {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
if (!isPos(temp)) {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
else{
cPrices[choice - 1] = temp;
beepBeep();
}
}else{
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
goto start;
}
// Allows the user to allow/disallow certain coin types.
void coinRule(bool arrAllow[], const long double arrVal[]) {
short choice;
char allow;
start:
cls();
cout << "Which coin type would you like to Allow/Disallow?" << endl;
// Prints out Coin types one-by-one as well as saying if they are allowed or not.
for (short i = 0; i < 7; i++) {
if (arrAllow[i] == true) {
cout << (i + 1) << ") " << setw(4) << arrVal[i] << " BAM, it is set to: TRUE." << endl;
}
else if (arrAllow[i] == false){
cout << (i + 1) << ") " << setw(4) << arrVal[i] << " BAM, it is set to: FALSE." << endl;
}
}
cout << "0) Return." << endl << "~> "; // If the user made a mistake and wanted to go back.
cin >> choice;
beepBeep();
if (choice == 0) {
cls();
return;
}
if ((choice >= 1) && (choice <= 7)) {
if (arrAllow[(choice - 1)] == true) {
arrAllow[(choice - 1)] = false;
}
else if (arrAllow[(choice - 1)] == false) {
arrAllow[(choice - 1)] = true;
}
}
else {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
}
goto start;
}
// Allows the user to change the names of offered coffees.
void coffeeName(string cTypes[]) {
short choice;
start:
cls();
cout << "Which coffee name would you like to modify?" << endl;
for (short i = 0; i < 5; i++) {
cout << (i + 1) << ") " << cTypes[i] << "." << endl;
}
cout << "0) Return." << endl << "~> ";
cin >> choice;
beepBeep();
if (choice == 0) {
cls();
return;
}
if ((choice >= 1) && (choice <= 5)) {
// discard remaining characters in the input stream
cin.ignore(numeric_limits<streamsize>::max(), '\n');
/*
* This is because otherwise the function would automatically input a "." into the array...
* TYSM Şukru!
*/
cout << cTypes[choice - 1] << " ~> ";
getline(cin, cTypes[choice - 1]);
beepBeep();
}
else {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
}
goto start;
}
// Shows the status and settings of all the functions.
void stat(const long double arrVal[], double cPrices[], string cTypes[], int coinAmnt[], int cAmnt[], bool arrAllow[]) {
short choice = 0, strSize = charCount(cTypes);
start:
loading();
cls();
//boundary();
cout << "Coffee details:" << endl;
for (short i = 0; i < 5; i++) {
cout << (i + 1) << ") " << setw(strSize + 1) << cTypes[i] << ": "; print(to_string(cPrices[i]), cPrices[i], 9); cout << " KM. " << setw(18) << "Amount left: " << cAmnt[i] << endl;
}
loading();
//boundary();
cout << endl;
cout << "Monetary details:" << endl;
for (short i = 0; i < 7; i++) {
if (arrAllow[i] == true) {
cout << (i + 1) << ") " << setw(4) << arrVal[i] << " BAM, it is set to: TRUE. " << setw(18) << "Amount Left: " << coinAmnt[i] << endl;
}
else if (arrAllow[i] == false) {
cout << (i + 1) << ") " << setw(4) << arrVal[i] << " BAM, it is set to: FALSE. " << setw(17) << "Amount Left: " << coinAmnt[i] << endl;
}
}
cout << endl << endl << "Input 0 to Return." << endl << "~> ";
cin >> choice;
if (choice == 0){
beepBeep();
cls();
return;
}
else {
cout << "Your input is invalid, try again";
error();
cinFlush();
pause();
goto start;
}
}
// Gives the user a menu of the above functions to choose from.
void settingModeMenu(const long double arrVal[], double cPrices[], string cTypes[], int coinAmnt[], int cAmnt[], bool arrAllow[]) {
short choice;
system("color e");
beepBeep();
start:
cls();
cout << "Which menu would you like to access?" << endl;
cout << "OPTIONS:\n1) Stored coffee.\n2) Stored coins.\n3) Change prices.\n4) Change Allowed coins.\n5) Change coffee names.\n6) Stats.\n0) Return." << "\n~> ";
cin >> choice;
beepBeep();
switch (choice) {
case 1:
coffeeInvent(cAmnt, cTypes);
break;
case 2:
coinInvent(coinAmnt, arrVal);
break;
case 3:
changePrices(cPrices, cTypes);
break;
case 4:
coinRule(arrAllow, arrVal);
break;
case 5:
coffeeName(cTypes);
break;
case 6:
stat(arrVal, cPrices, cTypes, coinAmnt, cAmnt, arrAllow);
break;
case 0:
cls();
system("color f");
beepBeep();
return;
default:
cout << "Your input is invalid, try again";
error();
cinFlush;
pause();
break;
}
goto start;
}