Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stuck on If Statement 1

Status
Not open for further replies.

nitroman84

Technical User
May 10, 2011
5
US
Hello, I'm still very green in programming with Fortran.
I have hit a brick wall in an If Statement in my program.

I am making a calculator to simplify caloric intake needs based on body fat % and lean body mass.

Caloric need is calculated as body fat % 6 to 13 Multiply LBM * 12,
body fat % 14 to 19 Multiply LBM * 11 and body fat % 20 and above Multiply LBM * 10
Here is the If Statement:

!BFPcent is body fat percent
!CF is Caloric Formula
!LeanBM is Lean body mass

If (BFPcent <= 13) Then
CF = (LeanBM * 12)
Else If (BFPcent >= 14) Then
CF = (LeanBM * 11)
Else If (BFPcent >=20) Then
CF = (LeanBM * 10)
End If

The code does work however the >= 14 seems to cancel out the >= 20 so no matter what figure I put in higher than 19 is still being calculated at 11 instead of 10.

Any help would be greatly appreciated.
Thanks
 
Try
Code:
If (BFPcent <= 13) Then
    CF = (LeanBM * 12)
Else If (BFPcent <= 19) Then
    CF = (LeanBM * 11)
Else
    CF = (LeanBM * 10)
End If
Since it is not <=13, it must be > 13. The next integer > 13 is 14 so there is no need to test for this. The next bit is to satisfy <= 19. If it is not <= 19, it must be > 19. The next integer > 19 is 20. Since that satisfies all further conditions, there is no need to test for it.
 
Thank you so much for the help. Fixed my problem and now the rest of the code works flawlessly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top