-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmi.cpp
45 lines (33 loc) · 933 Bytes
/
bmi.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
#include "bmi.h"
#include "ui_bmi.h"
bmi::bmi(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::bmi)
{
ui->setupUi(this);
setFixedSize(480, 140);
}
bmi::~bmi()
{
delete ui;
}
void bmi::on_bmiCalculateBtn_clicked()
{
if (ui->weightInput->text().isEmpty() || ui->heightInput->text().isEmpty()) {
QMessageBox::warning(this, "Error!", "Please enter a decimal or integer input.");
return;
}
double weight = ui->weightInput->text().toDouble();
double height = ui->heightInput->text().toDouble();
double bmi = (weight / (height*height));
QString status = "";
if (bmi > 0 && bmi < 18.5)
status = "Underweight";
else if (bmi >= 18.5 && bmi < 25.0)
status = "Normal";
else if (bmi >= 25.0 && bmi <= 40.0)
status = "Overweight";
msgClass = new msg();
msgClass->setValues(QString::number(bmi), status);
msgClass->show();
}