Results 1 to 3 of 3

Thread: Help with basic AUtoLISP calculator

  1. #1
    Woo! Hoo! my 1st post
    Join Date
    2018-10
    Posts
    1
    Login to Give a bone
    0

    Default Help with basic AUtoLISP calculator

    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)
    
          
      )
    Last edited by rkmcswain; 2018-12-10 at 03:31 PM. Reason: added [CODE] tags

  2. #2
    All AUGI, all the time
    Join Date
    2010-06
    Posts
    962
    Login to Give a bone
    0

    Default Re: Help with basic AUtoLISP calculator

    Hi,

    I have modified your codes a bit and I kept the codes simple just for learning.
    Code:
    (DEFUN C:CALC (/ ANS NUM1 NUM2 OPER)
      (SETQ NUM1 (GETREAL "\nENTER A NUMBER: "))
      (SETQ OPER (getstring "\nenter math operator +,-,*,/"))
      (SETQ NUM2 (GETREAL "\nENTER NEXT NUMBER:"))
      (COND
        ((= OPER "+")
         (SETQ ANS (+ NUM1 NUM2))
         (WHILE (SETQ NUM2 (GETREAL "\nEnter Another number to sum :"))
            (SETQ ANS (+ ANS NUM2))        
         )
        )
        ((= OPER "-") (SETQ ANS (- NUM1 NUM2)))
        ((= OPER "*") (SETQ ANS (* NUM1 NUM2)))
        ((= OPER "/") (SETQ ANS (/ NUM1 NUM2)))
      )
      (if ans (PROMPT (strcat "\nTHE ANSWER IS: " (rtos ANS 2))))
      (PRINC)
    )

  3. #3
    All AUGI, all the time
    Join Date
    2003-07
    Posts
    561
    Login to Give a bone
    0

    Default Re: Help with basic AUtoLISP calculator

    My version just type
    'cal 2*3
    6 will appear

Similar Threads

  1. Replies: 0
    Last Post: 2017-09-13, 05:53 PM
  2. Stair Calculator?
    By barrie.sharp in forum Revit Architecture - General
    Replies: 8
    Last Post: 2011-05-27, 02:01 PM
  3. Calculator?
    By david_peterson in forum Revit Structure - General
    Replies: 10
    Last Post: 2009-07-22, 03:11 PM
  4. can you create plans in revit? basic basic
    By comical_wenger in forum Revit Architecture - General
    Replies: 5
    Last Post: 2009-06-22, 01:36 PM
  5. calculator
    By kornackiph in forum Revit Structure - Wish List
    Replies: 3
    Last Post: 2007-09-17, 11:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •