Code Red > AutoLISP (Vanilla / Visual)

Challenge ( cylinder volume )

<< < (2/5) > >>

MP:
Another fun variant --


--- Code: ---(defun c:foo ( / foo )
    (defun foo ( pmt ) (initget 7) (getdist pmt))
    (princ
        (strcat "Volume of cylinder = "
            (rtos
                (   (lambda ( radius height )
                        (*  pi
                            (expt radius 2)
                            height
                        )
                    )
                    (foo "\nEnter radius: ")
                    (foo "\nEnter height: ")
                )
            )
        )   
    )
    (princ)
)
--- End code ---

MP:
And for a daffy combination of the two previous variants --


--- Code: ---(defun c:foo ( )
    (princ
        (strcat "Volume of cylinder = "           
            (rtos
                (   (lambda ( foo )
                        (   (lambda ( radius height )
                                (*  pi
                                    (expt radius 2)
                                    height
                                )
                            )
                            (foo "\nEnter radius: ")
                            (foo "\nEnter height: ")
                        )
                    )
                    (lambda ( pmt ) (initget 7) (getdist pmt))
                )   
            )
        )   
    )
    (princ)
)
--- End code ---

:P

whdjr:
Here's mine:


--- Code: --- ;Calculate the volume of a cylinder given diameter and height. However,
 ;to make it a challenge you can not use any variables. You must prompt
 ;the user for for both diameter and height, include error checking for
 ;negative numbers, zero and <enter>. Local functions are allowed.
 ;
 ;
 ;
 ;Cylinder pi * radius2 * height
 ;
 ;
 ;
(defun c:cylinder (/ ask sq)
 (defun ask (msg)
  (initget 7)
  (getreal msg)
 )
 (defun sq (num)
  (* num num)
 )
 (princ
  (strcat "\nCylinder Volume:    "
  (rtos (* pi
   (sq (ask "\nEnter Diameter for Cylinder:  "))
   (ask "\nEnter Height for Cylinder:  ")
)
2
  )
  )
 )
 (princ)
)
--- End code ---

Mark:
Will I'd say you copied my idea but you posted first. :-)


--- Code: ---(defun c:cubevol ( / ask)

  (defun ask (msg)
    (initget 7)
    (getreal msg)
    )

  (princ
    (strcat "Volume = "
            (rtos
              (*
                (* pi
                   (expt (/ (ask "\nDiameter: ") 2) 2)
                   )
                (ask "\nHeight: ")
                )
              )
            )
    )
  (princ)
  )

--- End code ---

Kerry:
Nice challenge Mark .. :-)

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version