09-09 Class Notes CS 107

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

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

View Full Document Right Arrow Icon
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) {
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 / 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 Right Arrow Icon
Ask a homework question - tutors are online