Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Powerpoint switch1

200 views

Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

Powerpoint switch1

  1. 1. Switch example 1 http://eglobiotraining.com.#include <iostream>using namespace std;int main(void){ char grade; cout << "Enter your grade: "; cin >> grade; switch (grade) { case a:case A: cout << "Your average must be between 90 - 100" << endl; break; case b: case B: cout << "Your average must be between 80 - 89" << endl; break; case c: case C: cout << "Your average must be between 70 - 79" << endl; break; case d: case D: cout << "Your average must be between 60 - 69" << endl; break; default: cout << "Your average must be below 60" << endl; }return 0;}
  2. 2. Screenshot http://eglobiotraining.comEnter your grade: 1Your average must be below 60
  3. 3. Switch example 2• #include <iostream> http://eglobiotraining.com• using namespace std;• int main()• {• int choice;• cout << "MENUnn";• cout << "1." << "t" << "Lobstern";• cout << "2." << "t" << "Steakn";• cout << "3." << "t" << "Turkeyn";• cout << "4." << "t" << "Hambergern";• cout << "5." << "t" << "Vegetariannn";• cout << "Choose your dinner entree: ";• cin >> choice;• cout << endl;• switch (choice)• {• case 1: cout << "Lobster is my favorite! Dig in!nn";• break;• case 2: cout << "Yummy! Steak is great...n"• << "but limit yourself to once a week," << endl• << "or risk the chance of high cholesterol!nn";• break;• case 3: cout << "Turkey is healthier than steak! ...Enjoy!nn";• break;• case 4: cout << "Hamburger is another form of steak. :-)nn";• break;• case 5: cout << "Finally, a vegitarian is in the house!nn";• break;• default: cout << "Invalid number, please enter a number"• << " from the entrees above.nn";• break;• }• return 0;• }
  4. 4. Screenshot http://eglobiotraining.comMENU 1. Lobster 2. Steak 3. Turkey 4. Hamberger 5. Vegetarian Choose your dinner entree: 2 Yummy! Steak is great... but limit yourself to once a week, or risk the chance of high cholesterol!
  5. 5. Switch example 3 http://eglobiotraining.com#include <iostream>using namespace std;int main(){ char letter; cout << "A)tHouse MDn" << "B)tAmerican Idlen" << "C)tFamily Guynn"; cout << "What TV show do you like (Enter A, B, C)?: "; cin >> letter; cout << endl; switch (toupper(letter)) { case A : cout << "Dr. House is a radical doctor!nn"; break; case B : cout << "Wannabe singers!nn"; break; case C : cout << "One of the craziest cartoons Ive ever seen.nn"; break; default: cout << "Invalid choice.nn"; break; } return 0;}
  6. 6. Screenshot http://eglobiotraining.com/ *============================[output]======== ========================= A) House MD B) American Idle C) Family Guy What TV show do you like (Enter A, B, C)?: a Dr. House is a radical doctor! Press any key to continue . . . =============================[output 2]================================ A) House MD B) American Idle C) Family Guy What TV show do you like (Enter A, B, C)?: z Invalid choice. Press any key to continue . . . ============================================ ==========================*/
  7. 7. Switch example 4 http://eglobiotraining.com#include <iostream>using namespace std;int main(){ int num; cout << "MENUnn"; cout << "1." << "t" << "Lobstern"; cout << "2." << "t" << "Steakn"; cout << "3." << "t" << "Turkeyn"; cout << "4." << "t" << "Hambergern"; cout << "5." << "t" << "Vegetariannn"; cout << "Choose your dinner entree: "; cin >> num; cout << endl; if (num == 1) { cout << "Lobster is my favorite! Dig in!nn"; } else if (num == 2) { cout << "Yummy! Steak is great...n" << "but limit yourself to once a week,n" << "or risk the chance of high cholesterol!nn"; } else if (num == 3) { cout << "Turkey is healthier than steak! ...Enjoy!nn"; } else if (num == 4) { cout << "Hamburger is another form of steak. :-)nn"; } else if (num == 5) { cout << "Finally, a vegitarian is in the house!nn"; } else { cout << "Invalid number, please enter a number" << " from the entrees above.nn"; }
  8. 8. Screenshot http://eglobiotraining.com/ *=====================[output]================ ======================= MENU 1. Lobster 2. Steak 3. Turkey 4. Hamberger 5. Vegetarian Choose your dinner entree: 5 Finally, a vegitarian is in the house! Press any key to continue . . . ============================[output 2]================================ MENU 1. Lobster 2. Steak 3. Turkey 4. Hamberger 5. Vegetarian Choose your dinner entree: 0 Invalid number, please enter a number from the entrees above. Press any key to continue . . . ============================================= =========================*/
  9. 9. Switch Example 5 http://eglobiotraining.com#include <stdlib.h>#include <stdio.h>int main(void) { int n; printf("Please enter a number: "); scanf("%d", &n); switch (n) { case 1: { printf("n is equal to 1!n"); break; } case 2: { printf("n is equal to 2!n"); break; } case 3: { printf("n is equal to 3!n"); break; } default: { printf("n isnt equal to 1, 2, or 3.n"); break; } } system("PAUSE"); return 0;}
  10. 10. Screenshothttp://eglobiotraining.com
  11. 11. http://eglobiotraining.com
  12. 12. http://eglobiotraining.com
  13. 13. Submitted to:Professor Erwin Globiohttp://eglobiotraining.com/

×