Text Boxes and Int

In the following code, I get an error stating "      Error      1 Cannot implicitly convert type 'int' to 'string".  I'm new at this and have no clue what's going on LOL.  Any help is appreciated.  I am trying to get the int "BMI" to display in the text box txtBMI.  Also, am I correct in "Height = int.Parse(txtHeight.text)" etc?

private void cmdCalculate_Click(object sender, EventArgs e)
        {
            int X;
            int Y;
            int Height;
            int Weight;
            int Z = 703;
            int BMI;

            Height = int.Parse(txtHeight.Text);
            Weight = int.Parse(txtWeight.Text);
            X = Weight / Z;
            Y = X / Height;
            BMI = Y / Height;

            txtBMI.Text = BMI;


        }
LVL 1
fattumsdadAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tinchosCommented:
You're getting the problem in the

            txtBMI.Text = BMI;
line

the problem is that the Text property is of type string and BMI is an integer

try using

            txtBMI.Text = BMI.ToString();

instead

Tincho
0
fattumsdadAuthor Commented:
tinchos,

That works, but it's giving me a value of "0"....  is my math wrong somewhere?
0
tinchosCommented:
If its showing a 0 then it's because that's the value of the variable

tell mewhat is it you're trying to get... so I can check it out

Tincho
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

tinchosCommented:
Keep in mind that the result of the division is an integer, so it cannot have decimal values....

so, if the result is 0.7, the result is going to be 0

Tincho
0
fattumsdadAuthor Commented:
It's a body mass index (BMI) calculator.  I takes your weight (txtWeight), multiplies it by 703 (int Z), divides by your height in inches twice (txtHeight).  I hope that makes sense...  it's hard to put in writing :)

The result should be somewhere between 18.5 and 30, usually.  
0
tinchosCommented:
Just to a little math

if

            X = Weight / Z;
            Y = X / Height;
            BMI = Y / Height;

            txtBMI.Text = BMI;

then

BMI = Y / Height; and Y = X / Height;

so

BMI = X / ( Height * Height ) and  X = Weight / Z;

so

BMI = Weight / (Height * Height * 703)

Keep in mind that in order to get BMI > 0

Weight  > Height * Height * 703

Tincho
0
fattumsdadAuthor Commented:
But, technically...  that doesn't work....  say weight is 150....  and height is 64 inches....

150 * 703 = 105450
105450 / 64 = 1647.65625
1647.65625 / 64 = 25.74462890625

Going with Weight / (height * height * 703).....

150 / (64 * 64 * 703)....  
150 / (4096 * 703)...
150 / 2879488 = 19196.586666666666666666666666667

Two completely different numbers....  now, I'm not excellent at math, so I could have the order of operations completely twisted...  if so, please correct me.  
0
tinchosCommented:
If the first piece is what you're trying to get, then you must check that in your code you're making

            X = Weight / Z;                      // In your last post you're making     X = Weight * Z instead of it
            Y = X / Height;
            BMI = Y / Height;

Tincho
0
tinchosCommented:
If you want to accomplish

150 * 703 = 105450
105450 / 64 = 1647.65625
1647.65625 / 64 = 25.74462890625

then you should make

private void cmdCalculate_Click(object sender, EventArgs e)
        {
            int X;
            int Y;
            int Height;
            int Weight;
            int Z = 703;
            int BMI;

            Height = int.Parse(txtHeight.Text);
            Weight = int.Parse(txtWeight.Text);
            X = Weight * Z;
            Y = X / Height;
            BMI = Y / Height;

            txtBMI.Text = BMI;


        }

Hope this helps

Tincho
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fattumsdadAuthor Commented:
Tincho,

Works great!  Thank you so much for the help, I really appreciate it!!!

Tony
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.