View Single Post
Old 02-20-2006, 04:40 PM   #3 (permalink)
AngelicVampire
Insane
 
AngelicVampire's Avatar
 
Code:
if (totalsales < 100 && totalsales > 1.00);   <------ error 1
{
          { < ---- Error 2
                 comission = totalsales * .05;
}
else
     if
     { <----- Error 3:
                    (totalsales >= 100 && totalsales < 300); <----- error 4
                          {
                                 totalsales * .10 = comission;
                          }

                          else
                                  (totalsales >=300)


                          comission = totalsales * .15;
                  }
  }

What you probably want is:

Code:
if (totalsales < 100 && totalsales > 1.00)
    comission = totalsales * .05;
else
    if(totalsales >= 100 && totalsales < 300)
        totalsales * .10 = comission;
    else
        comission = totalsales * .15;
That should work. Your braces are wrong and you are including comments (total sales > 300 etc) within else statements, else statements do not contain logic, they simply are the "all others case".

If you want to use braces, you shouldn't need to however, an if statement without braces automatically includes the next line (in this case an if statement such that we have multiple lines), this would be wrong:

Code:
if (some condition)
    Statement1;
    Statement2;
is equivalent to:

Code:
if (some condition)
{
    Statement1;
}
Statement2;
Code:
if (totalsales < 100 && totalsales > 1.00)
{
    comission = totalsales * .05;
} else
{
    if(totalsales >= 100 && totalsales < 300)
    {
        totalsales * .10 = comission;
    } else
    {    
        comission = totalsales * .15;
    }
}

Last edited by AngelicVampire; 02-20-2006 at 04:44 PM..
AngelicVampire is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62