Exercise 1:
Write a program that asks the user to input the amount they owe
and reports the amount they should pay as tip.
In this program, write and use a function called findTip that will
take in the amount owed and return the tip. The tip should be 15% of
the amount owed (multiply by .15).
My answer
Call-by-reference functions are particularly useful when returning more than one value from a function. Try the following exercises with call-by-reference functions:
Exercise 2:
Write a program that takes in three numbers and then reports back
the numbers, each decreased by one. If the user enters 4 -6 10.3, the
program will print out 3 -7 9.3
In this program, write and use a function called
decreaseByOne(num1,num2,num3) where the inputs are
called-by-reference. The inputs hold the numbers provided by the
user. After decreaseByOne has been called, each variable will hold the
initial number values minus one.
My answer
Exercise 3:
Write a progam that asks a user for an integer and reports the
first three multiples of the integer (i.e., the number times 2, the
number times 3, the number times 4). If the user enter 5, the program
will print out 10 15 20
In this program, write and use a function called
multiples(initialNum,numX2,numX3,numX4) where the first input is the
initial number and the other three inputs are variables that are
called-by-reference so they will hold the multiples of the initial
number after the function "multiples" has been called.
My answer