Ok so we just started learning scheme in class and our first assignment was given. Now I am new to scheme so I am still unsure if what I did is correct or not, but so far I am having a problem with my code for one of the homework questions.
Question 3:
3.1 Define a global name PI and associate the value 3.14159265 to it. [3]
3.2 Define a global Scheme procedure (areac d) that has the same function as defined in the C-program. [3]
3.3 Define a global Scheme procedure (volumec d h) [3]
3.4 Define a global Scheme procedure (TotalVolume) ; no parameter [3]
3.5 Define a global Scheme procedure (main) ; no parameter
This is sample C code that was given for us to go off of
#include <stdio.h>
const double PI = 3.14159265;
double areac(double d) {
double a;
a =PI*(d/2)*(d/2);
return a;
}
double volumec(double d, double h) {
double a, v;
a = areac(d); // call areac() here
v = a*h/3;
return v;
}
double TotalVolume() {
double v1, v2, v3, v4, v5;
v1 = volumec(1, 1);
v2 = volumec(2, 2);
v3 = volumec(3, 3);
v4 = volumec(4, 4);
v5 = volumec(5, 5);
return v1+v2+v3+v4+v5;
}
void main() {
TotalVolume();
And this is what I have for scheme:
(define PI 3.14159265)
(define (areac d)
(let*
(
(a (* (* PI (/ d 2)) (/ d 2)))
)
(display a)))
(define (volumec d h)
(let
(
(a (areac(d))))
(let ((v (/ (* a h) 3)))
(display v) ))
)
(define (TotalVolume)
(let*
(
(v1 (volumec(1 1)))
(v2 (volumec(2 2)))
(v3 (volumec(3 3)))
(v4 (volumec(4 4)))
(v5 (volumec(5 5)))
)
(display (+ (+ (+ (+ v1 v2) v3) v4) v5))))
(define main
(TotalVolume))
However I get an error when I run my program:
application: not a procedure;
expected a procedure that can be applied to arguments
given: 1
arguments...:
I get an error on the TotalVolume procedure and it points from (volumec(1 1)) to (let*
If anyone could help me out with what I am doing wrong that would be appreciated
Thanks!