计日程序(球拍)

Day counter program (racket)

我需要做一个程序来计算从 2000 年到用户在输入中输入的日期已经过去的所有天数。

当前代码。

#lang racket
(define (bisiesto year)
   (cond (= (remainder year 4) 0) (void))
)

(define day 0)
(define month 0)
(define cyear 0)

(define (count)
  (display "Enter day: ")
  (set! day(read))
  (newline)
  (display "Enter month: ")
  (set! month(read))
  (newline)
  (display "Enter year: ")
  (set! cyear(read))
  (newline)

  (cond
     ((and(> day 0)(>= 31))

我不知道如何继续这个程序,我不太了解球拍语言。

PD:如果我的英语不够好,请见谅,谢谢您的帮助。

您将需要函数 find-seconds from racket/date 库:

#lang racket

(require racket/date)

(define (day-count day month year)
  (let ((diff (- (find-seconds 0 0 0 day month year)
                 (find-seconds 0 0 0 1 1 2000))))
    (if (> 0 diff)
        "Inserted date is before 1. 1. 2000."
        (/ diff (* 60 60 24)))))

(define (read-with-prompt text)
  (display text)
  (flush-output)
  (read))

(define (run-program)
  (day-count
   (read-with-prompt "Enter day (1-31): ")
   (read-with-prompt "Enter month (1-12): ")
   (read-with-prompt "Enter year: ")))

(run-program) 开始并输入一些数字。