-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.cpp
More file actions
119 lines (93 loc) · 1.76 KB
/
Copy pathwidget.cpp
File metadata and controls
119 lines (93 loc) · 1.76 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
#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
setControl();
}
Widget::~Widget()
{
delete ui;
}
void Widget::changeMoney(int coin)
{
money += coin;
ui->lcdNumber->display(money);
setControl();
}
void Widget::setControl()
{
ui->pbCoffee->setEnabled(money>=200);
ui->pbMilk->setEnabled(money>=100);
ui->pbTea->setEnabled(money>=150);
}
void Widget::on_pbCoin500_clicked()
{
changeMoney(500);
}
void Widget::on_pbCoin100_clicked()
{
changeMoney(100);
}
void Widget::on_pbCoin50_clicked()
{
changeMoney(50);
}
void Widget::on_pbCoin10_clicked()
{
changeMoney(10);
}
void Widget::on_pbMilk_clicked()
{
changeMoney(-100);
}
void Widget::on_pbCoffee_clicked()
{
changeMoney(-200);
}
void Widget::on_pbTea_clicked()
{
changeMoney(-150);
}
//void
void Widget::on_pbReset_clicked()
{
char result[200];
int count500 = 0;
int count100 = 0;
int count50 = 0;
int count10 = 0;
while(1){
if(money >= 500){
count500 += 1;
money -= 500;
continue;
}
if(money >= 100){
count100 += 1;
money -= 100;
continue;
}
if(money >= 50){
count50 += 1;
money -= 50;
continue;
}
if(money >= 10){
count10 += 1;
money -= 10;
continue;
}
break;
}
QMessageBox msgBox;
sprintf(result,"500 : %d, 100 : %d, 50 : %d, 10 : %d", count500, count100, count50, count10);
msgBox.setText(result);
msgBox.exec();
ui->lcdNumber->display(money);
setControl();
return;
}