Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am working on a code writing assignment and I am not sure what I am doing wron

ID: 3866808 • Letter: I

Question

I am working on a code writing assignment and I am not sure what I am doing wrong. The assignment is from 'An Introduction to Using Visual Basic' by Schneider on page 268 and it is problem 27 Ideal Body Weight. Below is what I have written so far. When I run the program the only 2 lines appear (63 & 70) instead of numbers 63-70 and the calculation for the weight is wrong also, but I have no errors.

Dim lower, upper As Integer

Dim WomansWeight As Integer
Dim MensWeight As Integer
LstWeightTable.Items.Clear()
MensWeight = (Height * 4) - 128
WomansWeight = (Height * 3.5) - 108
lower = CInt(InputBox("Enter lower bound on height in inches:"))
upper = CInt(InputBox("Enter upper bound on height in inches:"))
LstWeightTable.Items.Add(" " & "Weight " & " " & "Weight")
LstWeightTable.Items.Add("Height" & " " & "Women " & " " & "Men")
LstWeightTable.Items.Add(lower.ToString & " " & WomansWeight.ToString & " " & MensWeight.ToString)
LstWeightTable.Items.Add(upper.ToString & " " & WomansWeight.ToString & " " & MensWeight.ToString)

The Question is:

According to researchers at Stanford Medical School, the ideal weight for a woman is found by multiplying her height in inces by 3.5 and subtracing 108. The ideal weight for a man is found by multiplying his height in inches by 4 and subtracing 128. Request the lower and upper bound for heights and then produce a table giving the ideal weights for women and men in that height range.

Explanation / Answer

Possible errors in your code.

1) If you want to display a range of values say from 63 to 70, then you need to run a loop in your program which will start from initial condition(say 63) to final condition say 70. So according to your problem you need to run a loop from lower height range to upper height range.

2) Now for each value of the loop, you need to calculate MensWeight and WomansWeight and add it to the table.

For Height = lower To upper ' Loop from lower range to upper range of height

WomansWeight = (Height * 3.5) - 108   'Calculate the Woman's weight for the height value in each loop execution

MensWeight = (Height * 4) - 128 ' Calculate the Men's weight for the height value in each loop execution

' Then add each value to the LstWeightTable

LstWeightTable.Items.Add(Height.ToString & " " & WomansWeight.ToString & " " & MensWeight.ToString)

These above statements are the basic calculation part of your program. Hope this will help you.

Corrected vb code

Dim lower, upper As Integer

Dim WomansWeight As Integer
Dim MensWeight As Integer
LstWeightTable.Items.Clear()

lower = CInt(InputBox("Enter lower bound on height in inches:"))
upper = CInt(InputBox("Enter upper bound on height in inches:"))

For Height = lower To upper ' Loop from lower range to upper range of height

WomansWeight = (Height * 3.5) - 108   'Calculate the Woman's weight for the height value in each loop execution

MensWeight = (Height * 4) - 128   ' Calculate the Men's weight for the height value in each loop execution

' Then add each value to the LstWeightTable

LstWeightTable.Items.Add(Height.ToString & " " & WomansWeight.ToString & " " & MensWeight.ToString)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote