Scope

In a function definition, any pair of curly braces { ... }) define the scope of the code that is in between them. A variable cannot be accessed outside of the scope that it is declared in. In fact, it does not exist outside of the scope that it is declared in.

Any pair of braces, whether they are a part of a function definition, an if statement, or a loop, defines its own scope that restricts the availability of any variables declared within them.

Add the following code to your showCookTimeForTurkey function:

v​o​i​d​ ​s​h​o​w​C​o​o​k​T​i​m​e​F​o​r​T​u​r​k​e​y​(​i​n​t​ ​p​o​u​n​d​s​)​ {​ ​ ​ ​ ​i​n​t​ ​n​e​c​e​s​s​a​r​y​M​i​n​u​t​e​s​ ​=​ ​1​5​ ​+​ ​1​5​ ​*​ ​p​o​u​n​d​s​;​ ​ ​ ​ ​p​r​i​n​t​f​(​"​C​o​o​k​ ​f​o​r​ ​%​d​ ...

Get Objective-C Programming: The Big Nerd Ranch Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.