OMEGA-ThundeR Posted December 8, 2017 Share Posted December 8, 2017 Hi, I'm trying to get an avarage height between 2 z-values. However in the calculation part i get a 'error: bad function: "11.30"' error (height of first point in this case). As far as i can tell my calculation part seems to be right, but it won't seem to accept the value. What is going wrong? (Defun c:zavg (/ punta puntb za zb tot avg) (setq punta (getpoint "\nKies het eerste punt")) (setq puntb (getpoint "\nKies het tweede punt")) (setq za (caddr (trans punta 1 0)) za (rtos za 2 2)) (setq zb (caddr (trans puntb 1 0)) zb (rtos zb 2 2)) (setq tot (+ za zb)) (setq avg (/ tot 2)) (princ avg) ) Quote Link to comment Share on other sites More sharing options...
MJLM Posted December 8, 2017 Share Posted December 8, 2017 You are trying to add two strings! First do the math, then convert them to strings. Quote Link to comment Share on other sites More sharing options...
OMEGA-ThundeR Posted December 8, 2017 Author Share Posted December 8, 2017 (edited) Removing the rtos part seem to do the trick . (Defun c:zavg (/ punta puntb za zb tot avg) (setq punta (getpoint "\nKies het eerste punt:")) (setq puntb (getpoint "\nKies het tweede punt:\n")) (setq za (caddr (trans punta 1 0))) (setq zb (caddr (trans puntb 1 0))) (setq tot (+ za zb)) (setq avg (/ tot 2)) (acet-ui-status (strcat "Hoogte 1e punt: "(rtos za)"\nHoogte 2e punt: "(rtos zb)"\nDe gemiddelden hoogte is: " (rtos avg 2 2)) "Gemiddelde hoogte") (princ) ) Thanks. Edited December 8, 2017 by OMEGA-ThundeR Quote Link to comment Share on other sites More sharing options...
Tharwat Posted December 8, 2017 Share Posted December 8, 2017 Hi, You did convert the variables (za & zb) to strings then you are trying to sum the two values and that is the error message that the program indicating to. One solution: (setq tot (+ (distof za) (distof zb))) Quote Link to comment Share on other sites More sharing options...
BIGAL Posted December 8, 2017 Share Posted December 8, 2017 Like others you used getpoint which is xyz and you want it as numbers so no Rtos, end result may need a rtos to make the (princ (strcat "average is " (rtos avg 2 2))) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.