I tried using logical operators in if statements when combining 2 conditions in one IF statement.
I still fail to understand the difference between || and &&, could some one help please?
In this example when I calculate the body mass index value that has been inputted, it doesn't give me the right description, for the 2nd and 3rd IF statement. Also, how do I round BMI result into the nearest 10?
namespace draft {
public partial class Form1: Form {
public Form1() {
InitializeComponent();
}
private void btn1_Click(object sender, EventArgs e) {
double weight = Convert.ToDouble(tbweight.Text);
double height = Convert.ToDouble(tbheight.Text);
double BMI = weight / Math.Pow(height, 2);
lbresult.Text = "BMI Result: " + BMI;
if (BMI < 18.5) {
lbdescription.Text = "BMI Description: Your weight is extremely low";
return;
}
if (BMI <= 18.5 && BMI < 25.0) {
lbdescription.Text = "BMI Description: Your weight is in line with average";
}
if (BMI <= 25.0 && BMI < 30.0) {
lbdescription.Text = "BMI Description: Your weight is over";
}
if (BMI >= 30.0) {
lbdescription.Text = "BMI Description: Your weight is excess";
}
}
}
}