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){...
Type: Posts; User: matsp
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){...
Although it probably is a good idea to range-check the values.
--
Mats
You probably don't want to set the value of sum to zero in EACH iteration of the loop...
--
Mats
And your sum is still undefined... (Yes, you've declared the variable, but never set it to an initial value).
Mats
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
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...