cpts121-6-1 - CptS 121 Fall 09 Lecture 6-1 HK Chapter 4:...

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

View Full Document Right Arrow Icon
1 CptS 121 L6-1 – 9/28/09 Prof. Chris Hundhausen CptS 121 Fall ‘09 Lecture 6-1 HK Chapter 4: Selection Structures (cont.) Lecture Outline I. switch statements I. Another example
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 CptS 121 L6-1 – 9/28/09 Prof. Chris Hundhausen switch Statements One issue with nested if statements is readability The deeper the nesting, the more difficult it can be to figure out what's happening Another issue is that the programmer could mistakenly "mis-nest" if statements, as in the previous example In cases in which the nesting is based on the value of a single variable, a switch statement may be a better alternative
Background image of page 2
3 CptS 121 L6-1 – 9/28/09 Prof. Chris Hundhausen switch Statement Scenario Let's revisit the previous baseball scenario: A high school baseball team awards merit points to players based on their offensive performance. A single (encoded 's') is worth 1 point, a double (encoded 'd') is worth 2 points, a triple (encoded 't') is worth 3 points, and a home run (encoded 'h') is worth 4 points. Any at-bat that leads to an out (encoded 'o') worth 0 points. Write a C statement that, given an at-bat character, properly awards points.
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 CptS 121 L6-1 – 9/28/09 Prof. Chris Hundhausen
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/25/2011 for the course CPTS 121 taught by Professor Hundhaus during the Spring '09 term at Washington State University .

Page1 / 9

cpts121-6-1 - CptS 121 Fall 09 Lecture 6-1 HK Chapter 4:...

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

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