Cost calculator function

What is wrong with this calculation? I'm trying to have it return cost 3.00 for up to 16, then from 17-20 inclusive increase by .50, then from 21-24 inclusive another .50 and so forth. However this comes out with 1-19 returning 3.00 and 20-23 returning 3.50 etc. its skipping the first 4 and also not including the last digit of its range either.

1
2
3
4
5
6
7
8
9
10
11
12
 double delivery_charge (double ounce)
{
 double cost;
 int incr;
 cost = 3.00;
 incr = (ounce -16) /4;
 
 if (ounce <= 16;
   return cost;
 else
   return cost + (incr * 0.5);
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
double delivery_charge (const double ounce)
{
 const double cost = 3.00;
 double incr = (ounce -16.0) /4.0;

 
 if (ounce <= 16.0) { // ; removed semicolon, and placed parentheses
     return cost; // always use braces, even for 1 statement
 } 
 else {
   return cost + (incr * 0.5);
 }

}
Last edited on
Topic archived. No new replies allowed.