練習(駐車料金計算)
2007/05/11
2025/01/08
練習のため、また問題を取ってきた。
http://www.media.osaka-cu.ac.jp/~matsuura/2006-PP/index.html
課題3-1 (駐車料金)
A駐車場の料金は,60分まで1000円,以後,30分毎に600円です. 駐車する時間を分単位で入力し,駐車料金を求めるプログラム ParkingCharge を書いて下さい.while文の練習なので,while文を使うこと.回答
やっぱり、練習のために無理矢理再帰。
(defun prompt-read (prompt)
(format *query-io* "~a: " prompt)
(force-output *query-io*)
(read-from-string (read-line *query-io*)))
(defun parking-charge (m)
(labels ((how-match (m price)
(if (>= 30 m)
price
(how-match (- m 30) (+ price 600)))))
(how-match (- m 30) 1000)))
(format t "~a円~%" (parking-charge (prompt-read "駐車時間(分)")))
labelsばっかり使ってる。