now im on lesson 5

This is a discussion on now im on lesson 5 within the C++ Programming forums, part of the General Programming Boards category; the tutorial doesnt seem to be helping that much. i dont really understand lesson 5. any advice? mabe i just ...

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    28

    now im on lesson 5

    the tutorial doesnt seem to be helping that much. i dont really understand lesson 5.


    any advice?





    mabe i just need a break...
    Last edited by NiVaG; 09-24-2004 at 08:45 PM.

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    do you have any specific questions?

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    28

    .

    well ya, but you guys are going to get fed up with me if i ask all my questions about every lesson.

    but heres one or a few.

    it said that Switch case statements are a substitute for long if statements that compare to an integral value

    how does this have anything to do with if statements? and"that compare to an integral value " makes no sence to me.

    Code:
    switch ( value ) {
    case this:
      Code to execute if value == this
      break;
    case that:
      Code to execute if value == that
      break;
    ...
    default:
      Code to execute if value != this or that
      break;
    }
    then it said

    "The condition of a switch statement is a value. The case says that if it has the value of whatever is after that case then do whatever follows the colon"

    but in the example theres nothing for it to do....it just repeats itself..

    in one of the sample programs i uses the word void yet it doesnt tell you what that word is!

    now that i think about it, nothing in lesson 5 makes sence to me so.....
    if your wondering what my question is read lesson 5
    .
    Last edited by NiVaG; 09-24-2004 at 10:09 PM.

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    switch statements are simply a way to shorten your code. For example, rather than writing:
    Code:
    if (x==5)
      //do something
    else if (x==6)
      //do something else
    else if (x==7)
      //do something else
    //etc
    You can write this:
    Code:
    switch(x)
    {
    case 5:
      //do something
    break;
    case 6:
     //do something else
    break;
    case 7:
     //do something else
    break;
    }
    Which will probably make the code easier to read and a bit shorter if you have a bunch of values to test against.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Lesson #4 - The Quiz
    By oval in forum C# Programming
    Replies: 0
    Last Post: 04-27-2006, 09:31 AM
  2. Lesson #3 - Math
    By oval in forum C# Programming
    Replies: 2
    Last Post: 04-27-2006, 09:16 AM
  3. Lesson #2 for New Comers to C#
    By oval in forum C# Programming
    Replies: 0
    Last Post: 04-18-2006, 06:36 PM
  4. Confused by Lesson 14
    By Saelice in forum C++ Programming
    Replies: 2
    Last Post: 12-13-2004, 02:16 AM
  5. Lesson 4 of Tutorial
    By polonyman in forum C++ Programming
    Replies: 5
    Last Post: 09-09-2004, 07:36 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21