wrong result in bill calculation
I don't know what's wrong with my code, but the output isn't quite accurate.
The question is that the first 30 minutes are free and 0.20 is charged for every extra minute.
When I input 31 for minutes, the result is 10.00 instead of 10.20. Same goes for 32,33 and 34 minutes. It doesn't seem to calculate the cents.
I'm quite new...
Here's the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
const int REG_MINUTES = 30;
const double REG_CHARGE = 10.00;
const double REG_RATE = 0.20;
int regAmountDue(int minutes)
{
if (minutes <= REG_MINUTES)
{
return REG_CHARGE;
}
else
{
return REG_CHARGE + (minutes - REG_MINUTES) * REG_RATE;
}
}
|
You are dealing with decimals so the return type needs to be double not int.
double regAmountDue(int minutes)
Thanks! It works now!
Topic archived. No new replies allowed.