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
|
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<math.h>
#include<ctime>
#include<typeinfo>
#include<string>
#include<windows.h>
#include<wchar.h>
#include<stdio.h>
#include<MMsystem.h>
#include <chrono>
using namespace std;
void Intro()
{
PlaySound(TEXT("hello-4"), NULL, SND_SYNC);
cout << endl;
cout << "Welcome to the Mathematics Practice Software.\n" << endl;
cout << endl;
cout << "This program will help you practice math (+,-,*,/) by ";
cout << "giving you with randomly generated questions,\n";
cout << "problems are at different level of difficulty.\nThe ";
cout << "difficulty is determined by the number of digits in ";
cout << "the question.\nYou can specify the initial ";
cout << "number of digits. The program will also keep track ";
cout << "of your progress.\nAt the end of each session, you ";
cout << "may choose to continue or quit." << endl;
cout << endl;
cout << "Please choose the operation you want to practice today (+,-, /,or *): ";
}
void gen_numbers(int &min, int &max, int &val1, int &val2, int &dif)
{
min = int(pow(10, dif - 1));
max = int(pow(10, dif) - 1);
val1 = min + rand() % ((max + 1) - min);
val2 = min + rand() % ((max + 1) - min);
}
void ask_questions(bool &correct, int &chances, int &numr, int &numw, long double res, long double ans, char op)
{
if (cin.fail())
{
cout << "Error\n";
system("pause");
exit(0);
}
else
{
if (op == '/')
{
ans = ans * 100;
res = res * 100;
ans = ceil(ans);
if (res >= ans - 1 || res <= ans + 1)
{
cout << "correct answer" << endl;
numr++;
correct = true;
PlaySound(TEXT("app.wav"), NULL, SND_SYNC);
}
else
{
cout << "Incorrect!";
numw++;
correct = false;
chances--;
PlaySound(TEXT("sad.wav"), NULL, SND_SYNC);
}
}
else if (op != '/')
if (res == ans)
{
cout << "correct answer" << endl;
numr++;
correct = true;
PlaySound(TEXT("app.wav"), NULL, SND_SYNC);
}
else
{
cout << "Incorrect!";
numw++;
correct = false;
chances--;
PlaySound(TEXT("sad.wav"), NULL, SND_SYNC);
}
}
}
int main()
{
srand(time(0));
SYSTEMTIME time;
while (true)
{
GetLocalTime(&time);
wprintf(L"The local Time: %02d:%02d:%02d\n", time.wHour, time.wMinute, time.wSecond);
int dif;
Intro();
char op;
cin >> op;
if (op != ('-') && op != ('+') && op != ('*') && op != ('/'))//if not a valid operator
{
cout << "Invalid operator" << endl;
system("pause");
exit(0);
}
cout << "each increment in difficulty increments the number of digits inside each part of the question.\n";
cout << "Please enter the level of difficult (1 and up): ";
cin >> dif;
int min, max;//generate two random numbers in the range min and max of digit size as dif
int i;
int val1, val2;
double res;
double ans;
double score;
bool correct;
char con;
int chances;
do {
int numr = 0;
int numw = 0;
for (i = 0; i < 5; i++)//5 operations
{
chances = 3;
gen_numbers(min, max, val1, val2, dif);
if (op == '/')//for division operator if second value is zero then repeatedly generate
//second number until it is not a zero
{
if (!val2)
val2 = min + rand() % ((max + 1) - min) + 1;
}
if (val1 == 0 || val2 == 0)
{
cout << "error\n";
system("pause");
exit(0);
}
if (dif > 10)
{
cout << "our data types ant take more than 10 digits per value.\n";
system("pause");
exit(0);
}
do {
ans = 0;
//res stores user's answer, ans has correct answer for(j=0:j<3.j++)
cout << "what is " << val1 << " " << op << " " << val2 << ": ";
if (op == '*')
ans = val1 * val2;
else if (op == '/')
{
//divisionproblem(ans, val1, val2, dif);
ans = val1 / double(val2);
ans = ceil(ans * 100) / 100;
}
else if (op == '+')
ans = val1 + val2;
else if (op == '-')
ans = val1 - val2;
cin >> res;
ask_questions(correct, chances, numr, numw, res, ans, op);
} while (!correct && chances != 0);
}
score = ((double)numr / (numr + numw)) * 100;
cout << "score: " << score << "%" << endl;//no of correct/total
//callme(score);
if (score >= 80)
{
cout << "Exelent\n";
}
else if (score >= 60)
{
cout << "Work Harder!\n";
}
else
{
cout << "try again" << endl;
cout << "you Didnot Pass\n";
}
cout << "Continue? [Y/N]" << endl;
cin >> con;
if (con == 'N' || con == 'n')
{
GetLocalTime(&time);
wprintf(L"The local Time: %02d:%02d:%02d\n", time.wHour, time.wMinute, time.wSecond);
PlaySound(TEXT("song.wav"), NULL, SND_SYNC);
system("pause");// considering break;
break;
}
if (score >= 80)
{
dif++;
}
else if (score >= 60)
{
dif++;
}
else
cout << endl;
cout << "next stage\n ";
} while (con == 'Y' || con == 'y');
system("pause");
return 0;
}
}
|