I am trying to calculate the seats left in each class by subtracting "Enrollment" from "Capacity" and then printing the result in a separate function. However my open-seats function returns no value unless I use the display function. How can I fix this?
#lang racket
( define course-list (cons '("Dept" "Number" "Section" "Class Nbr" "Capacity" "Enrollment")
'(("CMSC" "201" "1" "1052" 100 30)
("CMSC" "341" "6" "7447" 40 27)
("CMSC" "341" "3" "7443" "40" 29)
("CMSC" "331" "5" "7746" 40 36)
("CMSC" "331" "6" "7747" 40 "40")
("CMSC" "471" "3" "8196" 40 31))
)
)
(define (open-seats section)
(for ([e (in-list course-list)])
(if (equal? section (string->number (list-ref e 2))) (- (list-ref e 4) (list-ref e 5)) 'something)
;(if (equal? section (string->number (list-ref e 2))) (display(- (list-ref e 4) (list-ref e 5))) 'something)
)
)
;test open-seats
(open-seats 1)
(define (report-open-seats list-of-courses)
(for ([e (in-list course-list)])
(if (and (number? (list-ref e 4)) (number? (list-ref e 5))) (displayln(string-append (list-ref e 0) (list-ref e 1) " (Section " (list-ref e 2) ")=> " (open-seats 1))) newline)
)
)
; leave the following function call intact
;(report-open-seats course-list)
To make up a list of the items you can use for/list like this:
(define (open-seats section)
(for/list ([e (in-list course-list)]
#:when (equal? section (string->number (list-ref e 2))))
(- (list-ref e 4) (list-ref e 5))))
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments