Section 5 - Section 5.1: What is a Function? Up until this...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Section 5.1: What is a Function? Up until this point, every line of code we've shown you has done a simple task, such as performing an arithmetic operation, or checking a boolean condition, or assigning to a variable. Functions allow you to do a whole lot in one line of code. Instead of performing a simple task, a single line of code can display a menu of choices, or compute complicated three- dimensional transformations, or even play Tetris! How is this possible? Functions allow you to group a series of steps under one name. Remember in Section 1.1 when we were baking chocolate chip cookies? We had to perform the following steps: place two eggs in a bowl add 1.5 c. butter to the eggs ... bake cookies for 10-12 minutes at 375 degrees or until brown In C++, and in most programming languages, you can give a name to a series of steps. Let's say we want to call this procedure "bake cookies". Then, our algorithm for baking cookies becomes: bake cookies We've just created a function to do the work for us. Don't get too excited - you still need
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

Section 5 - Section 5.1: What is a Function? Up until this...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online