Paul's Tutorials - logo2-1Functions



Reading

Read the first page below completely, and at least the "Overloaded Functions" section of the second. You may read the rest of the second page if you wish.

Extra Reading

Companion Video

Practice

Once you feel comfortable with the above content, complete the following practice programs.

Temperature Converter

Write a function celsius() to convert degrees Fahrenheit to degrees Celsius (The conversion formula is °C = 5/9 * (°F - 32)). Use it to print a Fahrenheit-to-Centigrade table for -40 to 220 degrees Fahrenheit, in increments of 10 degrees.

It is important to note that the expression 5/9 is 0 (integer division), so you need to divide 5.0 by 9.0 instead.

Extra Practice

Do any of the following:

Rectangle

Write a function createrect(int x, int y) that creates a rectangle out of x's.

For example, if you call createrect(5,4) you will receive:

xxxxx
x   x
x   x
xxxxx

HINT: you will need to use nested for loops like you did in the Right Triangle program.

Extra Practice

Rewrite the program so that it can do any of the following:


← Chapter 2 Overview 2-1 Functions 2-2 Arrays →