Premium Essay

Pt1430

In:

Submitted By sadapaper
Words 1005
Pages 5
Lab 9 Functions and Input Validation
Lab 9.1
Writing Your Own Function that Returns an Integer
Step 1: A function contains three parts: a header, a body, and a return statement. The first is a function header which specifies the data type of the value that is to be returned, the name of the function, and any parameter variables used by the function to accept arguments. The body is comprised of one or more statements that are executed when the function is called. In the following space, complete the following: (Reference: Writing Your Own Functions, page 225).

a. Write a function with the header named addTen.
b. The function will accept an Integer variable named number.
c. The function body will ask the user to enter a number and the add 10 to the number. The answer will be stored in the variable number.
d. The return statement will return the value of number.

Function integer add ten (integer number) Display “Enter a number:” Input c. 10
Set c. 10= number + 10
Return d. number Step 2: In the following space, write a function call to your function from Step 1.

Set number = addTen (number) Writing Your Own Function that Returns a Boolean Value
Step 1: A Boolean function will either return a true or a false value. You can use these functions to test a condition. They are useful for simplifying complex conditions that are tested in decision and repetition structures. In the following space, complete the following: (Reference: Returning Boolean Values, page 238).

a. Write a function with the header named gender.
b. The function will accept a Boolean variable named answer.
c. The function body will ask the user to enter their gender into the variable type and then determine if they are male or female with an if statement.
d. The return statement will return the value of answer.

Function Boolean gender

Similar Documents