Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help Turing Functions Assignment
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
JumpingLimaBean




PostPosted: Thu Apr 28, 2011 5:29 pm   Post subject: Help Turing Functions Assignment

So i was absent from school today, and it turns out my class learnt functions.

I have to do the following in one program:

Write a program that includes the following functions:
1. average - send two real numbers as parameters, and return the average of the two
numbers
2. isOdd - send an integer as a parameter, and return true if the number is odd, and
false otherwise.
3. distance - send two pairs of x and y coordinates as parameters, and return the
distance between the two points.
4. getInteger - send a string as a parameter. The string should represent the message
printed for the user. The method will print the message to the user, and then get
the user's input. The method should return the integer if it is valid input, or keep
requesting new input if the user does not provide valid input.


This makes no sense *<*
---

Also i have no idea what a parameter is
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Apr 28, 2011 5:36 pm   Post subject: RE:Help Turing Functions Assignment

What makes no sense? We have tutorials that you can use to catch up on particular material.

A function is just a way to encapsulate a block of code so that it can be easily re-used.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Raknarg




PostPosted: Thu Apr 28, 2011 6:10 pm   Post subject: Re: Help Turing Functions Assignment

http://compsci.ca/v3/viewtopic.php?t=14665
If you've ever done procedures, they're very similar.
JumpingLimaBean




PostPosted: Thu Apr 28, 2011 8:52 pm   Post subject: RE:Help Turing Functions Assignment

Ya we did procedures yesterday
JumpingLimaBean




PostPosted: Thu Apr 28, 2011 8:59 pm   Post subject: RE:Help Turing Functions Assignment

Okay i checked out Parameters but wtf.

i need to write this in procedure form.

I have to do this:
Write a program that includes the following functions:
1. average ? send two real numbers as parameters, and return the average of the two
numbers


i already created this-
var num1 : real
var num2 : real
var averages : real


procedure average
put "Enter a real number:"..
get num1

put "Enter a 2nd real number:"..
get num2

averages := (num1 + num2) / 2

put " The average of them is:",averages

end average

average



How do i incorporate parameters into the code
Tony




PostPosted: Thu Apr 28, 2011 9:02 pm   Post subject: RE:Help Turing Functions Assignment

code:

procedure hello(name : string)
   put "hello, ", name
end

hello("world")
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
JumpingLimaBean




PostPosted: Thu Apr 28, 2011 10:48 pm   Post subject: RE:Help Turing Functions Assignment

ya tony, but i still dont get how to use that for my code
Tony




PostPosted: Fri Apr 29, 2011 2:06 am   Post subject: RE:Help Turing Functions Assignment

What part of the example are you having problems with?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Raknarg




PostPosted: Fri Apr 29, 2011 1:50 pm   Post subject: RE:Help Turing Functions Assignment

You incorporate them the same way Tony did.

Turing:

procedure average (n1, n2 : int)


You can do stuff with those parameters.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: