我如何在 Scheme 中使用 "case" 条件
How I can use "case" conditional in Scheme
我需要使用 "case" 但我不明白如何使用它。
我必须做一个程序来读取一个月的数字,这个程序给出了这个月有多少天。
但是当我输入任何数字时,告诉我对象 xxx 不适用。
有人可以帮助我吗?
(clear)
(display "Ingrese Un numero de Mes: ")
(define mes (read))
(if (and (integer? mes)(>= mes 1)(<= mes 12))
(case (mes)
((4 6 9 11)(display 30))
((1 3 5 7 8 10 12) (display 31))
(else (display 28 ))
)
)
你的括号太多了。应该是 (case mes ...)
,而不是 (case (mes) ...)
。它不像 C 风格 switch
。 :-)
我需要使用 "case" 但我不明白如何使用它。 我必须做一个程序来读取一个月的数字,这个程序给出了这个月有多少天。 但是当我输入任何数字时,告诉我对象 xxx 不适用。 有人可以帮助我吗?
(clear)
(display "Ingrese Un numero de Mes: ")
(define mes (read))
(if (and (integer? mes)(>= mes 1)(<= mes 12))
(case (mes)
((4 6 9 11)(display 30))
((1 3 5 7 8 10 12) (display 31))
(else (display 28 ))
)
)
你的括号太多了。应该是 (case mes ...)
,而不是 (case (mes) ...)
。它不像 C 风格 switch
。 :-)