You have integer division.
This line is ok (just)
But this causes a problem:
sales =sales- 4/100*sales;
When evaluating the expression
, it proceeds from left to right. First divide 4 by 100, giving zero. (remember, those are integers). Next, multiply 0 by sales again giving zero.
It's best, unless you specifically want integers (it is ok for the loop counter
), use a decimal point to make the numbers a floating-point type.
sales = sales - 4.0/100.0 * sales;
Also, you need to calculate the profit inside the loop too, for each year.
Let's go back and look at this line again
. Because the calculation proceeds from left to right,
is done first. Sales is type
, so the result is
too. The same with the divide by 100 here. But it is less dangerous to not depend on the order of operations, use
or more simply