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

I am told to build a program called BMI calculator. It's just a simple program that prompts user to enter his/her height and weight, and then compute the BMI by the formula weight/(heightxheight). This is the code that I wrote..

double height=textBox1.Text;
int weight=textBox2.text;
double BMI = weight / (height * height);
MessageBox.Show("Your BMI is " + BMI);

it keeps saying things like "cannot implicitly convert" or "textbox does not contain definition".

Please help!

Can anyone tell me what's wrong in that?

2006-10-24 07:49:35 · 2 answers · asked by sylvdoanx 2 in Computers & Internet Programming & Design

2 answers

It's because height and weight are defined as different data types; one's a double and one's an int. You have to type cast one of them. So you don't lose precision, you should type cast the int into a double.

double BMI = ((double)weight)/(height*height);

That should fix it.

2006-10-24 07:59:41 · answer #1 · answered by Anonymous · 0 0

You are trying to perform an operation with two different types of variables. You should make "weight" a double also.

2006-10-24 15:00:38 · answer #2 · answered by Zombie 7 · 0 0

fedest.com, questions and answers