문제

I need help in adding the multiplication of values with variables and assigning these to a variable in Scheme.

for example I have..

(define overall 0)
(define part1 0.15)
(define part2 0.20)
(define part3 0.4)
(define usrInput1 0)
(define usrInput2 0)

..

I need to do something like

overall = usrInput*part1 + usrInput*part2 + part3

in Scheme

I know how to add 2 variables/scalars together, but here I am stuck, could you please advise...

thank you.

도움이 되었습니까?

해결책

(define overall (+ (* usrInput1 part1) (* usrInput1 part2) part3))

다른 팁

Remove the (define overall 0). Then define overall to be the expressions you gave, except in (fully parenthesized) prefix notation instead of infix:

(define overall (+ (* usrInput1 part1) (* usrInput2 part2) part3))

The syntax to call any function/operator call in scheme is (operator-name operand1 operand2 ... operandn), not matter whether the operands are scalars, variables or nested expressions.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top