
-----------------------------------
Jimbo1991
Tue Apr 22, 2008 12:08 pm

procedures and functions-project ideas needed?
-----------------------------------
i have a final project to do with turing, in which procedures and functions need to be used, can anybody give me some ideas that i could do for it? thanks

-----------------------------------
Tony
Tue Apr 22, 2008 12:31 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
absolutely anything. You should be refactoring your code into usable functions anyway.

-----------------------------------
Jimbo1991
Tue Apr 22, 2008 12:33 pm

Re: procedures and functions-project ideas needed?
-----------------------------------
and what exactly does that mean? im a noob when it comes to turing

-----------------------------------
Tony
Tue Apr 22, 2008 12:35 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
not just Turing
Code refactoring is any change to a computer program's code that improves its readability or simplifies its structure without changing its results.

-----------------------------------
Jimbo1991
Tue Apr 22, 2008 12:37 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
im still lost, even with wikipedia, how about an example please?

-----------------------------------
Tony
Tue Apr 22, 2008 12:42 pm

RE:procedures and functions-project ideas needed?
-----------------------------------

function say_hello()
   put "hello"
end say_hello

put "the program will now greed you"
say_hello()
put "the program is now finished"


-----------------------------------
Jimbo1991
Tue Apr 22, 2008 12:45 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
o ok, il have to check it out the next time i have a computer that has turing on it

-----------------------------------
Tony
Tue Apr 22, 2008 12:58 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
you could read more on this in tutorials via the Turing Walkthrough

-----------------------------------
Saad
Tue Apr 22, 2008 3:22 pm

Re: RE:procedures and functions-project ideas needed?
-----------------------------------

function say_hello()
   put "hello"
end say_hello

put "the program will now greed you"
say_hello()
put "the program is now finished"


Perhaps you were in a hurry but it should be procedure not function


procedure say_hello ()
    put "hello"
end say_hello

put "the program will now greed you"
say_hello ()
put "the program is now finished"



To answer your orignal question. Functions and procedures are used to put repetative code only once.

Consider the following


function GetInput (what : string) : string
    put what
    var input : string
    get input
    result input
end GetInput

var firstName := GetInput ("Please enter your first name")
var lastName := GetInput ("Please enter your last name")


Vs.


var firstName, lastName : string
put "Please enter your first name"
get firstName
put "Please enter your last name"
get lastName


-----------------------------------
Jimbo1991
Wed Apr 23, 2008 12:52 pm

RE:procedures and functions-project ideas needed?
-----------------------------------
finaly i understand! thanks
