English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I build a slightly more complicated BMI calculator and got the errror message "Expected class, delegate, enum, interface, or struct"

this is the code I wrote

{
double height = Convert.ToDouble(textBox1.Text);

double weight = Convert.ToDouble(textBox2.Text);

double BMI = weight / (height * height);
if (BMI >= 27.5)
{
MessageBox.Show("Be careful, you have high risk of heart disease and diabetes");
}
else
{if (BMI>=23 && BMI<=27.4)
{
MessageBox.Show("You have moderate risk of heart disease and diabetes");
}
else
{if (BMI>=18.5 && BMI<=22.9)
{
MessageBox.Show("Congratulations, you're on healthy range");
}
else
MessageBox.Show("You have Risk of nutritional deficiency diseases and osteoporosis");
}
}
}

2006-10-25 01:57:42 · 1 answers · asked by sylvdoanx 2 in Computers & Internet Programming & Design

1 answers

Hi -

You're writing in Visual C++, right?

Well, all of your code looks fine, but where did you "write" this? I assume you wrote it for the "code" section of your form, but you're missing the namespace header that defines this code as relevant to your form. It should look like this:

namespace WHATEVER {

double height = Convert.ToDouble(textBox1.Text...
double weight = Convert.ToDouble(textBox2.Text...

double BMI = weight / (height * height);
if (BMI >= 27.5)
{
MessageBox.Show("Be careful, you have high risk of heart disease and diabetes");
}
else
{if (BMI>=23 && BMI<=27.4)
{
MessageBox.Show("You have moderate risk of heart disease and diabetes");
}
else
{if (BMI>=18.5 && BMI<=22.9)
{
MessageBox.Show("Congratulatio... you're on healthy range");
}
else
MessageBox.Show("You have Risk of nutritional deficiency diseases and osteoporosis");
}
}
}

Hope that helps?

Rob

2006-10-26 17:19:01 · answer #1 · answered by Rob 3 · 0 0

fedest.com, questions and answers