Author |
Message |
JumpingLimaBean
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
|
|
|
![](images/spacer.gif) |
JumpingLimaBean
|
Posted: Thu Apr 28, 2011 8:52 pm Post subject: RE:Help Turing Functions Assignment |
|
|
Ya we did procedures yesterday |
|
|
|
|
![](images/spacer.gif) |
JumpingLimaBean
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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")
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
JumpingLimaBean
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Fri Apr 29, 2011 2:06 am Post subject: RE:Help Turing Functions Assignment |
|
|
What part of the example are you having problems with? |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|