program main
!
! Sample program of IF structure
! Cal. of Body Mass Index (BMI) value & Best Weight
!
implicit none
real :: h,w,bmi,wb
write(*,*) 'Input your height (cm)?'
read(*,*) h
write(*,*) 'Input your weight (kg)?'
read(*,*) w
h=h/100. ! Convert cm->m
bmi=w/h**2 ! =w/(h*h)
wb=22.*h**2 ! =22.0*(h*h)
write(*,1) bmi
1 format(' Your BMI value is ',f5.1)
if(bmi<18.5) then
write(*,*) 'Underweight (Thin)'
end if
if(bmi>=18.5 .and. bmi<25.0) then
write(*,*) 'Normal weight'
end if
if(bmi>=25.0 .and. bmi<35.0) then
write(*,*) 'Obesity (Class 1-2)'
end if
if(bmi>=35.0) then
write(*,*) 'Obesity (Class 3-4)'
end if
write(*,2)wb
2 format(' Your best weight is ',f5.1,' kg')
end program main
¼Â¹Ô·ë²Ì