条件语句错误的 BMI 计算器球拍
BMI calculator racket with conditional statements error
我试图在球拍中创建一个简单的 BMI 计算器,但我找不到使用条件的方法,它根本不起作用。 (我是球拍新手)
(define (BMI weight height)
(/ weight (* height height))
[cond ((and (<= 25)(< 30))(error "Normal"))]
[cond ((< 20)(error "Underweight"))])
- 使用 let 创建新的局部变量。
- 只使用一个 cond 不同的子句。
- 不要使用 error for output. You can use any other output function(打印、写入、显示...)或仅使用函数中的 return 字符串。
(define (BMI weight height)
(let ((value (/ weight (* height height))))
(cond ((> 18.5 value) "Underweight")
((and (> value 18.5)
(> 25 value)) "Normal")
(#true "Obese"))))
(BMI 62 1.85) -> "Underweight"
(BMI 85 1.85) -> "Normal"
(BMI 120 1.85) -> "Obese"
我试图在球拍中创建一个简单的 BMI 计算器,但我找不到使用条件的方法,它根本不起作用。 (我是球拍新手)
(define (BMI weight height)
(/ weight (* height height))
[cond ((and (<= 25)(< 30))(error "Normal"))]
[cond ((< 20)(error "Underweight"))])
- 使用 let 创建新的局部变量。
- 只使用一个 cond 不同的子句。
- 不要使用 error for output. You can use any other output function(打印、写入、显示...)或仅使用函数中的 return 字符串。
(define (BMI weight height)
(let ((value (/ weight (* height height))))
(cond ((> 18.5 value) "Underweight")
((and (> value 18.5)
(> 25 value)) "Normal")
(#true "Obese"))))
(BMI 62 1.85) -> "Underweight"
(BMI 85 1.85) -> "Normal"
(BMI 120 1.85) -> "Obese"