Exercises


  • Write a function that is passes an int and returns a double.
  • Write a function that returns the number of seconds in a year. Use the number it returns to figure out how many seconds there are in a century.
  • Write a function that is passed an integer and returns that integer multiplied by a number. Use constants.
  • Create a for loop goes from 1 to 50, each time calling a function which prints the number out.
  • Create a if statement that calls a function. Have the funtion return 1. What happens?
  • Create a function that converts Ounces to Pounds. Figure out how many pounds a 5 ounce taco is.
  • Try, inside a function, modifying one of its parameters. What happened to the variable you passed to the function after the function ended? Did it change? Why do you think this is? (The answer is in Chapter 6!)


Table of Contents

Procedures/Functions | Returning Values | Passing Variables | Using Functions
Function Overloading | Default Parameters | Exercises