CSCI 240 -- Function Worksheet 2

For each of the following functions write a prototype, the function, and a calling statement.

Function 1: Write a function called CalcAverage. This function takes as its arguments two integers. The first is a total from a number of items and the second represents the number of items. The function should calculate and return the average. Before the function returns, print a sentence stating what the average is.

 

Function 2: Write a function called FindSum. It takes no arguments. The function should prompt the user for integer values and add them up until a negative value is entered. The sum should then be returned.

 

Function 3: Write a function called PrintPageHeader. This function takes as its argument an integer which represents the page number of the page to be printed. The function should print "240Distributors Employee Report" and the page number centered on the top of a new page.

Assuming that the value 2 is passed to the function, the output should resemble:

                          240Distributors Employee Report                  Page: 2

 

Function 4: Write a function called UserChoice. It takes as its argument an integer that represents an upper bound. The function is to prompt the user to enter an integer between 1 and the upper bound. If the user enters a number less than 1, return -1. If the user enters a number greater than the upper bound, return 0. If the user enters a number between 1 and the upper bound, inclusive, return the user's number.

 

Function 5: Write a function called IsOdd. It takes as its argument an integer that is to be tested to see if it's odd. If the number is odd, return 1. If the number is even, return 0.

 

Function 6: Write a function called FigureTax. It takes as its argument a real number that represents the subtotal for a customer's purchase. The function should apply a 6.25% tax to the subtotal and return a grand total, which is equal to the subtotal plus the tax amount.