;;; ----------------------------------------------------------------------- ;; bmi.scm ;; This program prompts the user for his weight in pounds and ;; height in inches, computes the Body Mass Index (BMI) and displays ;; "Underweight" if BMI is less than 18, "Normal" if BMI is between ;; 18 and 25, and "Overweight" if BMI is greater than 25. ;; BMI is defined as weight, in kilograms, divided over the squared ;; height, in meters. ;;; ----------------------------------------------------------------------- (define (BodyMassIndex weight height) ; Takes weight in kilograms and height in meters. ; Returns the value of BMI rounded to the nearest integer. (round->exact (/ weight (* height height))) ) (define (main) (let ((kgInPound 0.4536) ; Declare some constants (metersInInch 0.0254)) (write-string "Enter your height in inches ==> ") (let ((height (* (read) metersInInch))) (write-string "Enter your weight in pounds ==> ") (let* ((weight (* (read) kgInPound)) (BMI (BodyMassIndex weight height))) (write-string "Your BMI = ") (write BMI) (newline) (if (< BMI 18) (write-line "Underweight") (if (<= BMI 25) (write-line "Normal") (write-line "Overweight") ) ) ) ) ) 0 ; Return value )