program main
  !
  ! Sample program of IF statement
  ! 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(*,*) 'Your BMI value is',bmi
  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(*,*) 'Your best weight is',wb,' kg'

end program main
¼Â¹Ô·ë²Ì