O
O
Odyvanchik2018-04-17 11:24:19
Windows Forms
Odyvanchik, 2018-04-17 11:24:19

Why does label5 display the same value despite the given numbers?

5ad5af13b02ab120469055.jpeg
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BodyState
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int m = Convert.ToInt32(textBox2.Text);
int h = Convert.ToInt32(textBox3.Text);
int x = m / (h*h);
if ((radioButton1.Checked == false) && (radioButton2.Checked == false))
{
MessageBox.Show("Specify gender!", "Help",
MessageBoxButtons.OK);
}
if ((radioButton1.Checked == true) || (radioButton2.Checked == true))
{
if (x < 20)
{
label5.Text = string.Format("You are underweight.");
}
if ((x >= 20 && x <= 25))
{
label5.Text = string.Format("Don't worry, your weight is normal and in harmony with the world.");
if ((x > 25) && (x <= 30))
{
label5.Text = string.Format("You should start taking care of your body; you are slightly overweight. Further accumulation of fat increases the risk of various diseases and deterioration general health.");
}
if ((x > 30) && (x < 35))
{
label5.Text = string.Format("You are clearly obese, so you should do your best to reduce this figure.");
}
if (x >= 35)
{
label5.Text = string.Format("You're obese; it's time to sound the alarm and start actively working on getting back in shape.");
}
}
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("Fill in the suggested empty fields. Enter values ​​as integers. Specify height in centimeters.", "Help",
MessageBoxButtons.OKCancel);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void button2_Click(object sender,
textBox2.Clear();
textBox3.Clear();
label5.Text = "";
radioButton1.Checked = false;
radioButton2.Checked = false;
}
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Kulbida, 2018-04-27
@bcwd

Judging by the formula, height must be indicated in meters, but you have it in centimeters, not 170 but 1.7, and when calculating, use not an integer data type (int), but a fractional one (float)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question