09-09 Class Notes CS 107

# 09-09 Class Notes CS 107 - 09-09 Class Notes CS 107 Friday...

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

I updated the sample code you can use for program #2 Announcements: Questions? if statements Last Time: if statements, continued The switch statement: a shortcut to multiple if-else statements simple while loop break and continue statements Today: [See other document under today's notes] if statements (continued from last time) /* Illustrating the switch statement Assume a program that prompts for your weight on earth and then gives you a menu of planet numbers to choose from for converting your weight to what it would be on that planet. One approach is to use multiple if statements: // Calculate weight on desired planet given earthweight and chosen planet if (menuOption==1) { planetWeight = earthWeight * 0.39; // Mercury } else if (menuOption==2) { planetWeight = earthWeight * 0.91; // Venus } else if (menuOption==3) { planetWeight = earthWeight * 0.38; // Mars } else { planetWeight = earthWeight - 1; // marketing ploy } Instead, we can use the "switch" statement shown below: */ switch ( menuOption) {

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

09-09 Class Notes CS 107 - 09-09 Class Notes CS 107 Friday...

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

View Full Document
Ask a homework question - tutors are online