Search:

Type: Posts; User: matsp

Search: Search took 0.12 seconds.

  1. Replies
    18
    Views
    3,513

    You CAN of course use if/else instead of...

    You CAN of course use if/else instead of switch/case - but consider what the compiler does if you have a value 8 for this:


    if(order==1){
    total=25.00;
    }
    else if (order==2){...
  2. Replies
    18
    Views
    3,513

    Although it probably is a good idea to...

    Although it probably is a good idea to range-check the values.

    --
    Mats
  3. Replies
    18
    Views
    3,513

    You probably don't want to set the value of sum...

    You probably don't want to set the value of sum to zero in EACH iteration of the loop...

    --
    Mats
  4. Replies
    18
    Views
    3,513

    And your sum is still undefined... (Yes, you've...

    And your sum is still undefined... (Yes, you've declared the variable, but never set it to an initial value).

    Mats
  5. Replies
    18
    Views
    3,513

    That looks better. Does it work? [You may find...

    That looks better. Does it work? [You may find that you get a strange result - what is sum before you start adding orders together?]

    --
    Mats
  6. Replies
    18
    Views
    3,513

    Your analyzis of what goes wrong is probably...

    Your analyzis of what goes wrong is probably incorrect - you are overwriting the "total" every time you select something, so if you order number 1 three times over, it will still end up with 2 times...
Results 1 to 6 of 6