-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinal.c
275 lines (226 loc) · 8.66 KB
/
final.c
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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
float addNum(float addend1, float addend2);
float subtractNum(float minuend, float subtrahend);
float multiplyNum(float multiplicand, float multiplier);
float divideNum(float dividend, float divisor);
int maxQuestions();
int maxValue();
int randomizing(int maxInput);
void delay(unsigned int secs);
void intro_loading();
void exit_loading(int overallScore, int overallQuestions);
int main()
{
int operatorChoice, num1, num2, maxValueInput, maxQuestionInput;
int score = 0, totalQuestions = 0, overallScore = 0, overallQuestions = 0;
char continueChoice, again;
printf("\n\n\n\n\n\n\t\t\t\t\t---------------------------------------------------------------\n");
printf("\t\t\t\t\t\t WELCOME TO JASMIN'S MATH RANDOMIZER TUTOR!\n");
printf("\t\t\t\t\t---------------------------------------------------------------\n");
printf("\n\t\t\t\t\t\t\t\t INTRODUCTION\n");
printf("\n\t\t\t\t\t Hello, young learner! Let's play a fun Math game!\n");
printf("\t\t\t\t\t You will answer fun Math questions that pop up randomly!\n");
printf("\t\t\t\t\tJust type your answer and let's see how many you can get right!\n");
printf("\n\t\t\t\t\t---------------------------------------------------------------\n");
printf("\n\t\t\t\t\tWould you like to continue?\n\t\t\t\t\tPress [Y] if YES and [N] if NO\n");
do
{
printf("\n\t\t\t\t\tEnter your choice: ");
scanf(" %c", &continueChoice);
if (continueChoice != 'Y' && continueChoice != 'y' && continueChoice != 'N' && continueChoice != 'n')
{
printf("\t\t\t\t\tOops! Choose between [Y] and [N] only.\n");
}
} while (continueChoice != 'Y' && continueChoice != 'y' && continueChoice != 'N' && continueChoice != 'n');
if (continueChoice == 'Y' || continueChoice == 'y')
{
intro_loading();
delay(1000);
}
else if (continueChoice == 'N' || continueChoice == 'n')
{
exit_loading(overallScore, overallQuestions);
delay(1000);
return 0;
}
do
{
score = 0;
totalQuestions = 0;
printf("\n\n\t\t\t\t\t--------------------------------------------------------------------------\n");
printf("\t\t\t\t\t\t\t\t MATH TUTOR MENU");
printf("\n\t\t\t\t\t--------------------------------------------------------------------------\n");
printf("\t\t\t\t\t\t\t\t [1] ADDITION\n\t\t\t\t\t\t\t\t [2] SUBTRACTION\n\t\t\t\t\t\t\t\t [3] MULTIPLICATION\n\t\t\t\t\t\t\t\t [4] DIVISION\n\t\t\t\t\t\t\t\t [5] EXIT");
printf("\n\t\t\t\t\t--------------------------------------------------------------------------\n");
printf("\t\t\t\t\tNow, pick a type of Math question.\n");
printf("\t\t\t\t\tYou can choose between addition, subtraction, multiplication, or division!\n");
do
{
printf("\n\t\t\t\t\tPick a Math game: ");
scanf("%d", &operatorChoice);
if (operatorChoice < 1 || operatorChoice > 5)
{
printf("\t\t\t\t\tOops! Choose a number between 1 and 5 only.\n");
}
} while (operatorChoice < 1 || operatorChoice > 5);
if (operatorChoice == 5)
{
exit_loading(overallScore, overallQuestions);
delay(1000);
return 0;
}
do
{
maxQuestionInput = maxQuestions();
float correctAnswers[maxQuestionInput];
float userAnswers[maxQuestionInput];
maxValueInput = maxValue();
srand(time(NULL));
totalQuestions = 0;
while (totalQuestions < maxQuestionInput)
{
num1 = randomizing(maxValueInput);
num2 = randomizing(maxValueInput);
switch (operatorChoice)
{
case 1:
correctAnswers[totalQuestions] = addNum(num1, num2);
printf("\n\t\t\t\t\tWhat is the sum of %d and %d: ", num1, num2);
break;
case 2:
if (num1 < num2)
{
int swap = num1;
num1 = num2;
num2 = swap;
}
correctAnswers[totalQuestions] = subtractNum(num1, num2);
printf("\n\t\t\t\t\tWhat is the difference of %d and %d: ", num1, num2);
break;
case 3:
correctAnswers[totalQuestions] = multiplyNum(num1, num2);
printf("\n\t\t\t\t\tWhat is the product of %d and %d: ", num1, num2);
break;
case 4:
if (num2 == 0)
{
num2 = 1;
}
correctAnswers[totalQuestions] = divideNum(num1, num2);
printf("\n\t\t\t\t\tWhat is the quotient of %d and %d: ", num1, num2);
break;
}
scanf("%f", &userAnswers[totalQuestions]);
totalQuestions++;
overallQuestions++;
if (userAnswers[totalQuestions - 1] == correctAnswers[totalQuestions - 1])
{
printf("\t\t\t\t\tGreat Job! Your answer is correct!\n");
score++;
overallScore++;
}
else
{
printf("\t\t\t\t\tNice Try! The correct answer is %.2f.\n", correctAnswers[totalQuestions - 1]);
}
}
printf("\n\t\t\t\t\tCONGRATULATIONS! You've completed the questions!\n");
printf("\t\t\t\t\tYour final score: %d/%d\n", score, totalQuestions);
printf("\n\t\t\t\t\tDo you want to try another problem?\n\t\t\t\t\tPress [Y] if YES or Press [N] if NO\n");
printf("\t\t\t\t\tEnter your choice: ");
scanf(" %c", &again);
if (again == 'n' || again == 'N')
{
system("cls");
delay(1000);
break;
}
score = 0;
} while (again == 'y' || again == 'Y');
} while (continueChoice == 'y' || continueChoice == 'Y');
return 0;
}
int maxQuestions()
{
int max_questions;
printf("\t\t\t\t\t--------------------------------------------------------------------------\n");
printf("\t\t\t\t\tHow many questions would you like to answer for this operation? ");
printf("\n\t\t\t\t\tEnter your choice: ");
scanf("%d", &max_questions);
while (max_questions <= 0 || max_questions > 10)
{
printf("\t\t\t\t\tOops! Choose a number between 1 and 10 only.\n");
printf("\n\t\t\t\t\tEnter your choice: ");
scanf("%d", &max_questions);
}
return max_questions;
}
int maxValue()
{
int max_value;
printf("\n\t\t\t\t\tWhat is the biggest number you'd like to use in the game?\n");
printf("\t\t\t\t\tEnter your choice: ");
scanf("%d", &max_value);
while (max_value <= 0 || max_value > 100)
{
printf("\t\t\t\t\tOops! Choose a number between 1 and 100 only.\n");
printf("\n\t\t\t\t\tEnter your choice: ");
scanf("%d", &max_value);
}
return max_value;
}
int randomizing(int maxInput)
{
return rand() % maxInput;
}
float addNum(float addend1, float addend2)
{
return addend1 + addend2;
}
float subtractNum(float minuend, float subtrahend)
{
return minuend - subtrahend;
}
float multiplyNum(float multiplicand, float multiplier)
{
return multiplicand * multiplier;
}
float divideNum(float dividend, float divisor)
{
return dividend / divisor;
}
void delay(unsigned int secs)
{
clock_t interval = clock() + secs;
while (interval > clock());
}
void intro_loading()
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\tStarting the program... Please wait! ");
for (int i = 1; i <= 25; i++)
{
Sleep(100);
printf("%c", 219);
}
system("cls");
}
void exit_loading(int overallScore, int overallQuestions)
{
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t\tExiting the program... Please wait! ");
for (int i = 1; i <= 25; i++)
{
Sleep(100);
printf("%c", 219);
}
system("cls");
printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
printf("\t\t\t\t\t\tTHANK YOU FOR VISITING JASMIN'S MATH RANDOMIZER TUTOR!\n");
printf("\t\t\t\t\t\t\t\tOverall Score: %d/%d\n\n\n\n\n", overallScore, overallQuestions);
}