-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
231 lines (209 loc) · 7.26 KB
/
main.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
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
#include <iostream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
using namespace std;
void mainscrn();
int calculate(char,int,int);
char choice();
void midscrn(char);
void rules();
void game(char ch);
void endscrn();
int main()
{
mainscrn();
getch();
system("cls");
char ch=choice();
getch();
system("cls");
midscrn(ch);
getch();
system("cls");
rules();
getch();
system("cls");
game(ch);
system("cls");
endscrn();
getch();
return 0;
}
void mainscrn()
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t MATHS GAME \n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
}
char choice()
{
char ch;
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t==============================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t==============================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tWhich mathematical skill do you want to test?";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t\tPress + for ADDITION";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t\tPress - for SUBTRACTION";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t\tPress * for MULTIPLICATION";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t\tPress / for DIVISION\n\t\t\t\t\t\t\t\t\t\t\t\t\t";
cin>>ch;
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t==============================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t==============================================\n";
return ch;
}
void midscrn(char ch)
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
switch(ch)
{
case'+':
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tSo you are good at ADDITION huhh??";
break;
case '-':
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tSo you are good at SUBTRACTION huhh??";
break;
case '*':
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tSo you are good at MULTIPLICATION huhh??";
break;
case '/':
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tSo you are good at DIVISION huhh??";
break;
default:
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tIt seems you have entered a wrong input.";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t Let's try again shall we? ;)";
getch();
system("cls");
choice();
break;
}
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\tWell we shall see your capabilities...\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
}
void rules()
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t\tHere are the rules...";
cout<<"\n\t\t\t\tThere are total 25 stages.";
cout<<"\n\t\t\t\tYou have got 3 lives";
cout<<"\n\t\t\t\tA simple equation shall appear before you.";
cout<<"\n\t\t\t\tYou can take all the time that you need to solve that equation.";
cout<<"\n\t\t\t\tThen enter your calculated result.";
cout<<"\n\t\t\t\tWith each correct answer you will earn 5 points.";
cout<<"\n\t\t\t\tFor every incorrect answer 2 points will be deducted.";
cout<<"\n\t\t\t\tUse of calculators not allowed";
cout<<"\n\n\nLet's get started then...";
}
void game(char ch)
{
int i,l=3,s=0;
for(i=0;i<25&&l>0;i++)
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t\t\t\t\t=======================================================================================\n";
cout<<"\n\t\t\t\t\t STAGE "<<i+1;
cout<<"\t\t\t\t\t\t\t\t\t\t"<<" SCORE\t"<<s;
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t LIVES\t"<<l;
cout<<"\n\t\t\t\t\t\t=======================================================================================\n";
srand(time(0));
int a=rand() % 100;
int b=rand() % 100;
int r;
cout<<"\n\n\n\t\t\t\t "<<a<<"\t"<<ch<<"\t"<<b<<"\t=\t";
cin>>r;
system("cls");
int res = calculate(ch,a,b);
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
if(r==res)
{
s+=5;
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t WELL DONE!!!!\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
}
else
{
s-=2;
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tOOPS!!!!";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\tOne life lost\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
l=l-1;
}
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t Your score is:\t"<<s;
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
getch();
system("cls");
}
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
if(l==0&&i<100&&s<25)
{
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tYou have used all your lives";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t Not that great at "<<ch<<"\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
}
else if(l==0&&s>25)
{
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t============================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\tIt seems you have used up all your lives";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\tBut hey!....You were pretty good!!!!!";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t============================================\n";
}
else
{
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t What are you??\n \t\t\t\t\t\t\t\t\t\t\t\t\t\t A Mathematician??";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t You are great at "<<ch;
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
}
getch();
system("cls");
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t Final score:\t"<<s<<"\n\t\t\t\t\t\t\t\t\t\t\t\t Lives Left:\t"<<l;
cout<<"\n\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
getch();
}
int calculate(char ch,int a,int b)
{
int c;
switch(ch)
{
case '+':
c=a+b;
break;
case '-':
c=a-b;
break;
case '*':
c=a*b;
break;
case '/':
c=a/b;
break;
default:
c=0;
}
return c;
}
void endscrn()
{
cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t GAME OVER \n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
cout<<"\t\t\t\t\t\t\t\t\t\t\t\t=================================\n";
getch();
}