Greetings! I'm learning LISP in an AutoCAD customization class in college. I wrote a calculator function with basic elements, and it works ok. Now I want to make it add more than 2 numbers, and I'm stuck. I can input more than the 2, but it only adds the first number and the last number input, not the total. I'm using "while" to make it loop, but I'm stuck. Can anyone help? Thanks in advance.
Laura
Here is the function:
Code:
(DEFUN C:CALC()
(SETQ NUM1(GETREAL "ENTER A NUMBER: "))
(SETQ OPER(getstring "\nenter math operator +,-,*,/"))
(SETQ NUM2(GETREAL "\nENTER NEXT NUMBER:"))
(COND
((= OPER "+")
(WHILE
(SETQ ANS (+ NUM1 NUM2))
(SETQ NUM1 (ANS))
(SETQ NUM2(GETREAL "\nENTER NEXT NUMBER:"))
)
))
((= OPER "-")
(SETQ ANS (- NUM1 NUM2))
)
((= OPER "*")
(SETQ ANS (* NUM1 NUM2))
)
((= OPER "/")
(SETQ ANS (/ NUM1 NUM2))
)
)
(PROMPT "THE ANSWER IS: " )(PRINC ANS)(PRINC)
)