-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHW5.cpp
More file actions
375 lines (304 loc) · 11.2 KB
/
HW5.cpp
File metadata and controls
375 lines (304 loc) · 11.2 KB
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
// #include <iostream>
// #include <iomanip>
// #include <cmath>
// using namespace std;
// char encryptLower(char letter, int shiftValue);
// char encryptLower(char letter, int shiftValue){
// shiftValue = shiftValue % 26;
// int newLetter = ((letter - 'a' + shiftValue) % 26) + 'a';
// if (newLetter < 'a') {
// newLetter += 26;
// }
// return newLetter;
// }
// int main(){
// //declare variables
// char userChar;
// int letterShift;
// char encryptedChar;
// //prompt user for their letter (lowercase)
// cout << "Enter the lowercase character to encrypt:" << endl;
// cin >> userChar;
// cout << "Enter the encryption value:" << endl;
// cin >> letterShift;
// //set up statement to shift the value
// encryptedChar = encryptLower(userChar, letterShift);
// if (userChar >= 'a' && userChar <= 'z'){
// cout << "Letter " << userChar << " was encrypted to " << encryptedChar << endl;
// }
// else{
// cout << "Letter " << userChar << " was encrypted to " << userChar << endl;
// }
// return 0;
// }
// #include <iostream>
// #include <iomanip>
// #include <cassert>
// using namespace std;
// int calculateTime(int targetSize){
// int time = 0;
// int currentSize = 1;
// int growthRate = 1;
// while (currentSize < targetSize) {
// time++;
// currentSize += growthRate;
// growthRate++;
// }
// return time;
// }
// int main(){
// //define variables
// int headSize;
// int midBodySize;
// int lowerBodySize;
// //prompt user 3 times for each part of the body
// do{
// cout << "Enter head size:" << endl;
// cin >> headSize;
// if (headSize <= 0){
// cout << "Please enter a positive integer for head size:" << endl;
// cin >> headSize;
// }
// }
// while (headSize <= 0);
// do{
// cout << "Enter mid-body size:" << endl;
// cin >> midBodySize;
// if (midBodySize <= 0){
// cout << "Please enter a positive integer for mid-body size:" << endl;
// cin >> midBodySize;
// }
// }
// while (midBodySize <= 0);
// do{
// cout << "Enter lower-body size:" << endl;
// cin >> lowerBodySize;
// if (lowerBodySize <= 0){
// cout << "Please enter a positive integer for lower-body size:" << endl;
// cin >> lowerBodySize;
// }
// }
// while (lowerBodySize <= 0);
// //calculate times
// int headTime = calculateTime(headSize);
// int midBodyTime = calculateTime(midBodySize);
// int lowerBodyTime = calculateTime(lowerBodySize);
// int totalTime = headTime + midBodyTime + lowerBodyTime;
// cout << "Time to reach head size: " << headTime << " seconds" << endl;
// cout << "Time to reach mid-body size: " << midBodyTime << " seconds" << endl;
// cout << "Time to reach lower-body size: " << lowerBodyTime << " seconds" << endl;
// cout << "Total time to create the snowman: " << totalTime << " seconds" << endl;
// return 0;
// }
// #include <iostream>
// #include <iomanip>
// #include <cmath>
// using namespace std;
// int main(){
// int userNum;
// int steps = 0;
// do{
// cout << "Enter a number between 10 and 500:" << endl;
// cin >> userNum;
// if (userNum <= 10 || userNum >= 500){
// cout << "Invalid input." << endl;
// }
// }
// while (userNum <= 10 || userNum >= 500);
// while (userNum != 1){
// if (userNum % 2 == 0){
// userNum = (userNum / 2);
// }
// else if (userNum % 2 != 0){
// userNum = (3*userNum) + 1;
// }
// cout << userNum << endl;
// steps++;
// }
// cout << "Total steps: " << steps << endl;
// return 0;
// }
// #include <iostream>
// #include <iomanip>
// using namespace std;
// //fuction to calculate potions
// int calculatePotions(int leaves, int flowers, int stools, int needles,
// int reqLeaves, int reqFlowers, int reqStools, int reqNeedles){
// int potionsTea = leaves/reqLeaves;
// int potionsSun = flowers/reqFlowers;
// int potionsToad = stools/reqStools;
// int potionsPine = needles/reqNeedles;
// //check ingredients
// int potions = potionsTea;
// if (potionsSun < potions){
// potions = potionsSun;
// }
// if (potionsToad < potions){
// potions = potionsToad;
// }
// if (potionsPine < potions){
// potions = potionsPine;
// }
// return potions;
// }
// void updateIngredients(int leaves, int flowers, int stools, int needles,
// int reqLeaves, int reqFlowers, int reqStools, int reqNeedles, int potionsMade){
// leaves -= potionsMade * reqLeaves;
// flowers -= potionsMade * reqFlowers;
// stools -= potionsMade * reqStools;
// needles -= potionsMade * reqNeedles;
// }
// int main(){
// int magicPotion;
// int healthPotion;
// int potionChoice;
// int tea, sun, toad, pine;
// int hPotionTea = 6, hPotionSun = 1, hPotionToad = 5, hPotionPine = 2;
// int mPotionTea = 2, mPotionSun = 3, mPotionToad = 10, mPotionPine = 1;
// do{
// cout << "Select a potion crafting priority:" << endl;
// cout << "1. Health Potion" << endl;
// cout << "2. Magic Potion" << endl;
// cin >> potionChoice;
// if (potionChoice != 1 && potionChoice != 2){
// cout << "Invalid input. Please select 1 or 2." << endl;
// cin >> potionChoice;
// }
// }while (potionChoice != 1 && potionChoice != 2);
// cout << "How many Tealeaves do you have?" << endl;
// cin >> tea;
// cout << "How many Sunflowers do you have?" << endl;
// cin >> sun;
// cout << "How many Toadstools do you have?" << endl;
// cin >> toad;
// cout << "How many Pine Needles do you have?" << endl;
// cin >> pine;
// magicPotion = 0, healthPotion = 0;
// if (potionChoice == 1){
// healthPotion = calculatePotions(tea, sun, toad, pine, hPotionTea,
// hPotionSun, hPotionToad, hPotionPine);
// updateIngredients(tea, sun, toad, pine, hPotionTea,
// hPotionSun, hPotionToad, hPotionPine, healthPotion);
// magicPotion = calculatePotions(tea, sun, toad, pine, mPotionTea,
// mPotionSun, mPotionToad, mPotionPine);
// }
// else if (potionChoice == 2){
// magicPotion = calculatePotions(tea, sun, toad, pine, mPotionTea,
// mPotionSun, mPotionToad, mPotionPine);
// updateIngredients(tea, sun, toad, pine, hPotionTea,
// hPotionSun, hPotionToad, hPotionPine, healthPotion);
// healthPotion = calculatePotions(tea, sun, toad, pine, hPotionTea,
// hPotionSun, hPotionToad, hPotionPine);
// }
// if (potionChoice == 1){
// cout << "You can make " << healthPotion << " Health potion(s) and " << magicPotion << " Magic potion(s)." << endl;
// }
// else if (potionChoice == 2){
// cout << "You can make " << magicPotion << " Magic potion(s) and " << healthPotion << " Health potion(s)." << endl;
// }
// return 0;
// }
// #include <iostream>
// #include <iomanip>
// using namespace std;
// int magicPotion(int teaLeaves, int sunFlowers, int toadStools, int pineNeedles){
// int mPotions = 0;
// while (teaLeaves >= 2 && sunFlowers >= 3 && toadStools >= 10 && pineNeedles >= 1){
// mPotions++;
// teaLeaves -= 2;
// sunFlowers -= 3;
// toadStools -= 10;
// pineNeedles -= 1;
// }
// return mPotions;
// }
// int healthPotion(int teaLeaves, int sunFlowers, int toadStools, int pineNeedles){
// int hPotions = 0;
// while (teaLeaves >= 6 && sunFlowers >= 1 && toadStools >= 5 && pineNeedles >= 2){
// hPotions++;
// teaLeaves -= 6;
// sunFlowers -= 1;
// toadStools -= 5;
// pineNeedles -= 2;
// }
// return hPotions;
// }
// int main(){
// int mPotion;
// int hPotion;
// int potionChoice;
// int tea, sun, toad, pine;
// do{
// cout << "Select a potion crafting priority:" << endl;
// cout << "1. Health Potion" << endl;
// cout << "2. Magic Potion" << endl;
// cin >> potionChoice;
// if (potionChoice != 1 && potionChoice != 2){
// cout << "Invalid input. Please select 1 or 2." << endl;
// cin >> potionChoice;
// }
// }while (potionChoice != 1 && potionChoice != 2);
// do{
// cout << "How many Tealeaves do you have?" << endl;
// cin >> tea;
// if (tea < 0){
// cout << "Invalid input. Please enter a non-negative integer." << endl;
// cin >> tea;
// }
// }while (tea < 0);
// do{
// cout << "How many Sunflowers do you have?" << endl;
// cin >> sun;
// if (sun < 0){
// cout << "Invalid input. Please enter a non-negative integer." << endl;
// cin >> sun;
// }
// }while (sun < 0);
// do{
// cout << "How many Toadstools do you have?" << endl;
// cin >> toad;
// if (toad < 0){
// cout << "Invalid input. Please enter a non-negative integer." << endl;
// cin >> toad;
// }
// }while (toad < 0);
// do{
// cout << "How many Pine Needles do you have?" << endl;
// cin >> pine;
// if (pine < 0){
// cout << "Invalid input. Please enter a non-negative integer." << endl;
// cin >> pine;
// }
// }while (pine < 0);
// mPotion = 0, hPotion = 0;
// switch (potionChoice){
// case 1:
// hPotion = healthPotion(tea, sun, toad, pine);
// mPotion = magicPotion(tea, sun, toad, pine);
// cout << "You can make " << hPotion << " Health potion(s) and " << mPotion << " Magic potion(s)." << endl;
// break;
// case 2:
// mPotion = magicPotion(tea, sun, toad, pine);
// hPotion = healthPotion(tea, sun, toad, pine);
// cout << "You can make " << mPotion << " Magic potion(s) and " << hPotion << " Health potion(s)." << endl;
// break;
// }
// return 0;
// }
// #include <iostream>
// #include <cmath>
// #include <cassert>
// using namespace std;
// bool validateInt(string input) {
// int len = input.length();
// if (len == 0) return false;
// int i = 0;
// if (input[0] == '-') {
// if (len == 1) return false;
// i = 1;
// }
// for (; i < len; i++) {
// if (input[i] < '0' || input[i] > '9') return false;
// }
// return true;
// }