acadstudent Posted December 9, 2013 Posted December 9, 2013 (edited) Good Morning, I again need some assistance with a lisp program to convert Celsius to Fahrenheit and vise versa, these will need to be in two separate programs in a single file. Here are my input and outputs needed: Input: Enter temperature in Celsius : x Ouput: x.x degrees Celsius is equivalent to xx.x degrees Farhrenheit. the second program will simply be flipped: Input: Enter temperature in Fahrenheit: x Output: xx.x degrees Fahrenheit equivalent to x.x degrees Celsius. The algorithms needed are: C= 5/9 (F-32) F= (9/5 ©) +32 Here is what I have thus far for setting Celsius to C and the formula for Celsius to F is represented by C2F: (defun C:CONV-TEMP ( / ) ;; Celsius to Fahrenheit (setq C (getreal "\nEnter temperature in Celsius: ") ) (setq C2F (+ (* (/ 9 5) C) 32) ) (textscr) (prompt (strcat (rtos F 2 1) "\ndegrees Celsius is equivalent to" (rtos C2F 2 1) "degrees Fahrenheit.")) ;;Fahrenheit to Celsius (setq F (getreal "\nEnter temperature in Fahrenheit: ") ) (setq F2C (* (- F 32) (/ 5 9)) ) (textscr) (prompt (strcat (rtos C 2 1) "\ndegrees Fahrenheit equivalent to" (rtos F2C 2 1) "degrees Celsius.")) );eop Thank you for any help/direction. Acadstudent Edited December 10, 2013 by CADTutor Original post restored Quote
MSasu Posted December 9, 2013 Posted December 9, 2013 Please look for INITGET and GETKWORD functions. Also, for user input, is a good programming practice to validate it: (if ([i]getsomething[/i]) (progn ;your processing ) ) Quote
acadstudent Posted December 9, 2013 Author Posted December 9, 2013 (edited) I'm receiving malformed list on input, but prior to debugging, is this what you're suggesting? (defun C:CONV-TEMP ( / ) ;; Celsius to Fahrenheit (initget 1 "Yes No") (if (="Yes" (getkword "\nConvert Celsius to Fahrenheit? [Yes/No]: " )) (setq C (getint (+ 1 2 "\nEnter temperature in Celsius: ") ) (setq C2F (+ (* (/ 9 5) C) 32) ) (textscr) (prompt (strcat (rtos F 2 1) "\ndegrees Celsius is equivalent to" (rtos C2F 2 1) "degrees Fahrenheit.")) ); Close first if statement (if (="No") (setq F (getreal "\nEnter temperature in Fahrenheit: ") ) (setq F2C (* (- F 32) (/ 5 9)) ) (textscr) (prompt (strcat (rtos C 2 1) "\ndegrees Fahrenheit equivalent to" (rtos F2C 2 1) "degrees Celsius.")) (princ) ) );close second if statement );eop Edited December 10, 2013 by CADTutor Original post restored Quote
MSasu Posted December 9, 2013 Posted December 9, 2013 That means that you have some un-balanced pharenthesis - please pay more attention to code formatting to be able to notice those issues by yourself. I have fixed your code; please compare it with yours to understand my changes (since I didn't commented them all). (defun C:CONV-TEMP( / [color=red]C C2F F F2C[/color] ) [color=red];localize variables[/color] (initget 1 "Yes No") (if (= "Yes" (getkword "\nConvert Celsius to Fahrenheit? [Yes/No]: " )) [color=red](progn [/color] ;; Celsius to Fahrenheit (setq C (getint "\nEnter temperature in Celsius: ")) [color=red];why constrain to integer?!?[/color] (setq C2F (+ (* (/ 9[color=red].0[/color] 5[color=red].0[/color]) C) 32)) [color=red];ALWAYS use real values for division[/color] (textscr) (prompt (strcat [color=red]"\n"[/color] (rtos C 2 1) " degrees Celsius is equivalent to " (rtos C2F 2 1) " degrees Fahrenheit.")) [color=red];spaces!!![/color] [color=red])[/color]; Close if branch [color=red](progn[/color] ;; Fahrenheit to Celsius (setq F (getreal "\nEnter temperature in Fahrenheit: ")) (setq F2C (* (- F 32) (/ 5[color=red].0[/color] 9[color=red].0[/color]))) [color=red];ALWAYS use real values for division[/color] (textscr) (prompt (strcat [color=red]"\n"[/color] (rtos F 2 1) " degrees Fahrenheit equivalent to " (rtos F2C 2 1) " degrees Celsius.")) ;spaces!!! [color=red])[/color]; Close else branch ) (princ) );eop Quote
satishrajdev Posted December 10, 2013 Posted December 10, 2013 Dear acadstudent, Dont reedit you post after getting solution for your problem, may other people are after the same issue... Quote
MSasu Posted December 10, 2013 Posted December 10, 2013 Acadstudent, please don't do this anymore! There may be others that will learn from this (complete) discussion. Or even you may be the one to benefit by getting better advice when the thread comes to attention of more experienced programmers. Quote
pBe Posted December 10, 2013 Posted December 10, 2013 aaaaaaaaaaaaaaaaaaaaaaaaaa What in the world is this? Quote
MSasu Posted December 10, 2013 Posted December 10, 2013 There were two code excerpts that got removed meantime. Quote
pBe Posted December 10, 2013 Posted December 10, 2013 There were two code excerpts that got removed meantime. Oops, sorry about that. i did not read thru the whole thread, I was starting to think you're a mind reader MSasu the way you replied with just a "shout" from the OP Quote
CADTutor Posted December 10, 2013 Posted December 10, 2013 I've restored the original posts so that this thread makes sense again. Quote
satishrajdev Posted December 10, 2013 Posted December 10, 2013 Well-done..... But OP should aware of such thing to not to do.... Quote
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.