-
Apr 3rd, 2014, 09:56 PM
#1
Thread Starter
New Member
[RESOLVED] Help with BMI program
Hi, I am running into a problem with my code, but I am not sure where.
I have tried putting the formula differently and even splitting it up.
Please help, lol.
Code:
Module Module1
Sub Main()
'Declarations
Dim intWeight As Integer = 0
Dim intHeight As Integer = 0
Dim dblBMI As Double = 0.0
Dim strEval As String = ""
'Get Height and Weight
getNumbers(intHeight, intWeight)
'Calculate the BMI
calculateBMI(intWeight, intHeight, dblBMI)
bmiEval(dblBMI, strEval)
'Display BMI
displayBMI(strEval, dblBMI)
terminateProgram()
End Sub
Private Sub getNumbers(ByRef intHeight As Integer, ByRef intWeight As Integer)
Console.Write("What is your height in inches? ")
intHeight = CInt(Console.ReadLine())
Console.Write("What is your weight in pounds? ")
intWeight = CInt(Console.ReadLine())
End Sub
Private Sub calculateBMI(ByVal intHeight As Integer, ByVal intWeight As Integer, ByRef dblBMI As Double)
dblBMI = (intWeight * 703) / (intHeight * intHeight)
End Sub
Private Sub bmiEval(ByVal dblBMI As Double, ByRef strEval As String)
If dblBMI >= 30.0 Then
strEval = "Obese"
ElseIf dblBMI >= 25.0 Then
strEval = "Overweight"
ElseIf dblBMI >= 18.5 Then
strEval = "Normal Weight"
ElseIf dblBMI >= 0 Then
strEval = "Underweight"
Else
strEval = "Cannot find BMI. Please try again."
End If
End Sub
Private Sub displayBMI(ByVal strEval As String, ByVal dblBMI As Double)
Console.WriteLine()
Console.WriteLine("Your BMI is " & dblBMI)
Console.WriteLine("Evaluation: " & strEval)
End Sub
Private Sub terminateProgram()
Console.WriteLine()
Console.Write("Press the enter key to terminate the program.")
Console.Read()
End Sub
End Module
-
Apr 4th, 2014, 04:21 AM
#2
Re: Help with BMI program
Hi, I am running into a problem with my code, but I am not sure where
Can you describe the problem/issue properly?
-
Apr 4th, 2014, 08:03 AM
#3
Re: Help with BMI program
Originally Posted by KGComputers
Can you describe the problem/issue properly?
Hear, hear. What do you expect to happen and what actually happens? If an exception is thrown, what's the error message?
-
Apr 4th, 2014, 11:15 AM
#4
Thread Starter
New Member
Re: Help with BMI program
It keeps on calculating wrong, but no error messages though. I expect the answer to be 19.59 or somewhere around that spot, but idk where its going wrong at. The formula should work...
Last edited by koomie; Apr 4th, 2014 at 12:07 PM.
-
Apr 4th, 2014, 05:09 PM
#5
Thread Starter
New Member
Re: Help with BMI program
Any help or clues/hints would be greatly appreciated.
This is due on monday
-
Apr 4th, 2014, 06:33 PM
#6
Addicted Member
Re: Help with BMI program
This is the line that causes the problem:
Code:
getNumbers(intHeight, intWeight)
change it like this:
Code:
getNumbers( intWeight,intHeight)
Last edited by Atenk; Apr 4th, 2014 at 06:39 PM.
-
Apr 4th, 2014, 07:40 PM
#7
Thread Starter
New Member
Re: Help with BMI program
Why would the positioning matter? (First time programmer ^^)
Edit: Also thank you! It worked like you said
Last edited by koomie; Apr 4th, 2014 at 07:49 PM.
-
Apr 4th, 2014, 08:16 PM
#8
Addicted Member
Re: [RESOLVED] Help with BMI program
I wanted to get by calculation, and not by code, the first wrong result = 2.7856185536973369850241827399336, so I changed the formula
like this: (68 * 703) / (131 * 131); and I got it.
Then I was convinced that one argument in one of the sub procedures was inverted.
In fact the argument to change, wasn't that In getNumbers, even if that gives the correct result.
The argument that should be inverted is that in calculateBMI:
Code:
Private Sub calculateBMI(ByVal intHeight As Integer, ByVal intWeight As Integer, ByRef dblBMI As Double)
dblBMI = (intWeight * 703) / (intHeight * intHeight)
End Sub
The right code is therefore:
Code:
Private Sub calculateBMI( ByVal intWeight As Integer, ByVal intHeight As Integer, ByRef dblBMI As Double)
If arguments must figure in a sub procedure, two things must be respected.
1-When the arguments are passed, they must respect the same number of arguments, with the same datatypes
2-the order of those arguments must also be respected.
Last edited by Atenk; Apr 4th, 2014 at 08:49 PM.
-
Apr 4th, 2014, 09:22 PM
#9
Thread Starter
New Member
Re: [RESOLVED] Help with BMI program
Okay, I am pretty sure I fully understand this problem now.
I will have to write these down in my notes so that I will remember these two rules and not make the same mistake again
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|