Conditional Statement Error?

Ryan-Walker

Usenet Archive
Joined
Aug 20, 2003
Messages
1
Reaction score
0
Please forgive my experience level, but when I try to run the following code, I get this error "; error: bad argument type: FILE 24.0". The "24.0" is the correct answer to the input I give. I have never seen this error in this format before. The idea behind this code is to formulate the "Power" when one variable is unknown. Any help is appreciated.

(defun c:power
(setq E (GETREAL "Voltage?:"))
(setq I (GETREAL "Amps?:"))
(setq R (GETREAL "Resisitance?:"))

(COND ((= E NIL) (PRINC (RTOS E1 2 3) (SETQ E1 (* (EXPT I 2) R)))) ;;IF NO VOLTAGE USE THIS FORMULA ((= I NIL) (PRINC (RTOS I1 2 3) (SETQ I1 (/ (EXPT E 2) R)))) ;;IF NO AMPERAGE USE THIS FORMULA ((= R NIL) (PRINC (RTOS R1 2 3) (SETQ R1 (* E I))))) ;;IF NO RESISTANCE USE THIS FORMULA (princ))
 
Like Mark says: set your variables before trying to (princ) them. I think this does what you're trying to do:

(defun c:power (/ e i r e1 i1 r1)
(setq E (GETREAL "Voltage?:"))
(setq I (GETREAL "Amps?:"))
(setq R (GETREAL "Resisitance?:"))
(COND
((not E)
(SETQ E1 (* (EXPT I 2) R))
(PRINC (RTOS E1 2 3))
)
((not I)
(SETQ I1 (/ (EXPT E 2) R))
(PRINC (RTOS I1 2 3))
)
((not R)
(SETQ R1 (* E I))
(PRINC (RTOS R1 2 3))
)
)
(princ)
)

However, you may want to include some instructions about leaving the unknown value blank ... the casual user may fill in all three values and, will then get nothing but a blank Command: prompt in response.
___
 
Thank you very much!

Paul said:
Like Mark says: set your variables before trying to (princ) them. I think this does what you're trying to do:

(defun c:power (/ e i r e1 i1 r1)
(setq E (GETREAL "Voltage?:"))
(setq I (GETREAL "Amps?:"))
(setq R (GETREAL "Resisitance?:"))
(COND
((not E)
(SETQ E1 (* (EXPT I 2) R))
(PRINC (RTOS E1 2 3))
)
((not I)
(SETQ I1 (/ (EXPT E 2) R))
(PRINC (RTOS I1 2 3))
)
((not R)
(SETQ R1 (* E I))
(PRINC (RTOS R1 2 3))
)
)
(princ)
)

However, you may want to include some instructions about leaving the unknown value blank ... the casual user may fill in all three values and, will then get nothing but a blank Command: prompt in response.
___
 

Latest threads

Back
Top