-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (63 loc) · 1.5 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
#include <iostream>
//#include <string>
//#include <math.h>
//#include <cmath>
//#include <stdio.h>
#include <windows.h>
using namespace std;
int generate(int highest) {
int random = 1000;
random = rand();
while (random > highest) {
random = rand();
}
return random;
}
bool question(int highest) {
int one = generate(highest), two = generate(highest), correct = one*two, answer = 0;
bool ifCorrect = false;
cout << "What is " << one << "x" << two << "=";
cin >> answer;
if (answer == correct) {
ifCorrect = true;
}
return ifCorrect;
}
int main() {
double highest = 100, asked = 0, correct = 0;
double percentage = 0.0;
cout << "Welcome to MathGame\nPick the highest number: ";
cin >> highest;
cout << "Answer the following questions\n\n";
while (true) {
bool yesNo = question(highest);
asked++;
if (yesNo) { //correctly
correct++;
percentage = correct / asked * 100;
cout << "Correct\nScore " << correct << "/" << asked << "\n" << percentage <<"%\n\n";
}
else {
percentage = correct / asked * 100;
cout << "Incorrect\nScore " << correct << "/" << asked << "\n" << percentage << "%\n\n";
}
}
}
/*
int main()
{
unsigned char b, f;
for (b = 0; b<16; b++)
{
for (f = 0; f<16; f++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), b << 4 | f);
printf("%.2X", b << 4 | f);
}
printf("\n");
}
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x07);
printf("\n");
return 0;
}
*/