Computer Science Canada my first turing program how is it |
Author: | JKJones [ Tue Oct 19, 2010 8:26 pm ] |
Post subject: | my first turing program how is it |
Hello i just signed up here but yeah this is my first turing program its just a simple calculator i know its probably garbage compared to most of the stuff on here but i just want to know what i can improve upon if theres errors things i should have done if the implementation is terrible if i wasted time with writing too much or something just generally i want to know what you think about it. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %Author: Jemar "JKJones" Jones %Date: 19/10/10 %Description :This program is a calculator used to multiply divide subtract % and add 2 numbers or more. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% var num1 : int var num2 : int var num3 : int var num4 : int var act : string var cont : int put "Hello this program is a simple caculator" put "Enter your first number please" get num1 loop loop put "please select your action (+), (-), (x), or (/)" get act exit when act = "+" or act = "-" or act = "/" or act = "x" or act = "X" put "I'm sorry it doesn't appear that that is a valid option try again please" end loop put "Enter your second number" get num2 if act = "/" and num2 = 0 then put "You can't divide by zero try again please" else exit end if end loop if act = "+" then num3 := num1 + num2 put num3 else if act = "-" then num3 := num1 - num2 put num3 else if act = "x" then num3 := num1 * num2 put num3 else if act = "/" then num3 := num1 div num2 put num3 else end if end if end if end if loop loop put "Press 1 if you want to continue with this number " put "or press any other number to end" get cont if cont = 1 then else put "Alright thanks for using this calc" quit end if loop loop put "please enter a function to use on ", num3 get act exit when act = "+" or act = "-" or act = "/" or act = "x" or act = "X" end loop put "please enter your next number" get num4 if act = "/" and num4 = 0 then put "You can't divide by zero try again please" else exit end if end loop if act = "+" then num3 := num3 + num4 put num3 else if act = "-" then num3 := num3 - num4 put num3 else if act = "x" then num3 := num3 * num4 put num3 else if act = "/" then num3 := num3 div num4 put num3 else end if end if end if end if end loop end loop |
Author: | SNIPERDUDE [ Tue Oct 19, 2010 8:36 pm ] | ||
Post subject: | Re: my first turing program how is it | ||
Cool. And for future reference the way to add Turing syntax tags in the forums here is:
|
Author: | JKJones [ Tue Oct 19, 2010 8:41 pm ] |
Post subject: | Re: my first turing program how is it |
K thanks i'll remember that next time |
Author: | JKJones [ Tue Oct 19, 2010 8:58 pm ] |
Post subject: | RE:my first turing program how is it |
Also i was a bit lazy here since i couldn't figure out how to do the loops properly or find a diffrent command i put a quit command when i wanted it to end this acts as a error can someone tell me what i should have done here? |
Author: | CWRules [ Tue Oct 19, 2010 9:22 pm ] |
Post subject: | RE:my first turing program how is it |
Not bad. Couple of suggestions: - Put a delay before the quit so you have time to see the "Thanks" line before the program quits. - Look into the getch command. It's handy for 'Press a key to continue' stuff. |
Author: | Coldkick [ Tue Oct 19, 2010 9:35 pm ] |
Post subject: | RE:my first turing program how is it |
Efficiency is important too, the less code that has the same effect, the less memory used. Look over your code, see if you can spot things that will do the same effect without using multiple lines. Not only will it have less memory usage, but it will look better too. Other than that it seems to run pretty well. |
Author: | JKJones [ Tue Oct 19, 2010 9:41 pm ] |
Post subject: | RE:my first turing program how is it |
Ya i thought to do the delay after i posted but it still says its a error when i use quit is there a better way? And cool could you maybe show me how you would use the getch command i kinda get it but the Turing reference is a little confusing. Thats good advice thanks I know very few things so i really abused loops and if statements to the limit here. |
Author: | SNIPERDUDE [ Wed Oct 20, 2010 1:53 pm ] |
Post subject: | RE:my first turing program how is it |
Remember a program will quit naturally when it has no more lines of code to read (in other words, it reaches the end). Something to take into consideration. |
Author: | JKJones [ Wed Oct 20, 2010 7:36 pm ] |
Post subject: | RE:my first turing program how is it |
Yeah, but i could only get it to exit out of the loop. I don't know how to get it to just skip all the other lines of the program, so i tried quit. |