"The delivery charge for the first pound (i.e., 16 ounces) is $3.00 and $0.50 is added to the charge for each additional 4 ounces. For example, a package weighing more that 16 ounces but at most 20 ounces costs $3.50 to deliver; a package weighing more than 20 but at most 24 ounces costs $4.00 to deliver; etc."
Here is the code i wrote for this:
Code: Select all
double price;
int over16;
over16 = ((oz - 16)/4);
over16 = over16 + 1;
if (oz <= 16)
price = 3.00;
else
price = 3.00 + (over16 /2)
This code works properly for every number except 20, 24, 28, 32....
Is there possibly any way that I can tell over16 that if the answer is an integer when it does the calculations (and its already defined as one), it will not add 1 to itself? That is the only problem, I just have no idea how to achieve this.
Does anyone have any suggestions for how I can fix this? I have been looking at it for a few days and nothing has popped into my brain yet. Thanks in advance for any help.