Thread: Switch Statements

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    4

    Switch Statements

    So in my computer science class my teacher refuses to help us.

    Someone else please help me with this :/

    Rerite the following nested if using a switch statement.

    if (Score == 1)
    cout << "Poor" << endl;
    else if (Score == 2)
    cout << "Fair" << endl;
    else if (Score == 3)
    cout << "Average" << end;
    else if (Score ==4)
    cout << "Good" << endl;
    else
    cout << "Excellent" << endl;

    Please help!

  2. #2

  3. #3
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    http://www.cprogramming.com/tutorial/lesson5.html

    I don't think it's a matter of your teacher refusing to help you but a matter of your teacher refusing to explain switch statements again because no one listened the first time around.
    Sent from my iPadŽ

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    Europe/Belgrade
    Posts
    78
    It's trivial if you read anu lesson about switch, but here's the code:

    Code:
    switch (Score)
    {
      case 1:
         cout << "Poor" << endl;
         break;
      case 2:
        cout << "Fair" << endl;
        break;
      case 3:
        cout << "Average" << end;
        break;
      case 4:
        cout << "Good" << endl;
        break;
      default:
        cout << "Excellent" << endl;
    }

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Hey thanks guys. I'll definetly read more about it. When I read it in my book it's like I have to decode the book too cuz its so confusing lol.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using Files Inside Switch Statements
    By arealfind08 in forum C Programming
    Replies: 11
    Last Post: 03-17-2009, 04:49 PM
  2. Explanation of switch statements
    By ammochck21 in forum C++ Programming
    Replies: 6
    Last Post: 11-04-2006, 01:59 PM
  3. arrays within switch statements
    By divinyl in forum C++ Programming
    Replies: 6
    Last Post: 07-17-2003, 01:56 PM
  4. help with switch statements
    By Wexy in forum C Programming
    Replies: 3
    Last Post: 11-06-2002, 04:44 PM
  5. Switch Statements
    By blackgingr in forum C Programming
    Replies: 3
    Last Post: 10-07-2002, 02:36 PM
Website Security Test