-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
155 lines (94 loc) · 2.45 KB
/
mainwindow.cpp
File metadata and controls
155 lines (94 loc) · 2.45 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
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <stdlib.h>
#include <math.h>
char operation = '+';
int answer;
int statment1;
int statment2;
int score = 0;
QString first = QString::number(statment1);
QString second = QString::number(statment2);
QString operation1 = QString(operation);
QString userinput;
QString textscore = QString::number(score);
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_ResetBtn_clicked()
{
getfact(operation);
}
void MainWindow::getfact(char operation)
{
switch(operation){
case '+':
statment1 = rand() % (10 + 1);
statment2 = rand() % (10 + 1);
answer = statment1 + statment2;
break;
case '-':
redosub:
statment1 = rand() % (10 + 1);
statment2 = rand() % (10 + 1);
answer = statment1 - statment2;
while(answer <= 0)goto redosub;
break;
case '*':
statment1 = rand() % (10 + 1);
statment2 = rand() % (10 + 1);
answer = statment1 * statment2;
break;
case '/':
redodiv:
statment1 = rand() % (10 + 1);
statment2 = rand() % (10 + 1);
if(statment1 == 0 || statment2 == 0)goto redodiv;
answer = statment1 % statment2;
while(answer <= 0)goto redodiv;
break;
default:
break;
}
first = QString::number(statment1);
second = QString::number(statment2);
operation1 = QString(operation);
ui->FirstStatment->setText(first);
ui->operatoText->setText(operation1);
ui->SecondStatment->setText(second);
}
void MainWindow::on_SubmitBtn_clicked()
{
userinput = ui->lineEdit->text();
if(userinput.toInt() == answer)
{
score ++;
}else score --;
textscore = QString::number(score);
ui->scoretext->setText(textscore);
getfact(operation);
}
void MainWindow::on_comboBox_currentIndexChanged(int index)
{
//remember that the index is an array
switch(index)
{
case 0:
operation = '+';
break;
case 1:
operation = '-';
break;
case 2:
operation = '*';
break;
case 3:
operation = '/';
break;
}
}