Reputation: 67
My objective is to make a procedure which subtracts one TriVol from another but unfortunately I keep getting this error:
contract violation expected: number? given: # argument position: 1st other arguments.
(The error occurs on the DiffVol procedure) What is the meaning of the error and why is it happening and how do I fix it? Thank you!
(define (TriArea base height) (* height (/ base 2)))
(define (TriVol)
(define base (read))
(define height (read))
(define depth (read))
(* depth (TriArea base height))
(display (* depth (TriArea base height))))
(define (DiffVol)
(display(- (Trivol) (TriVol))))
Upvotes: 0
Views: 67
Reputation: 27414
Remember that each function returns the value of its last form. So, the reason for the error is that the function TriVol
does not return an integer, but a void value, since its last form is display
.
So, in function DiffVol
, the form (- (TriVol) (TriVol))
, that should do the difference between two integers, finds two void values and gives the error.
To correct the error, simply change the code of TriVol
to return the right value.
Upvotes: 1