You're correct! Sorry for such a trivial posting all........ I thought it was another error in the book.....
Thanks for the help Martyn!
Pete
Quote:
quote:Originally posted by Martyn
Pete,
The book is right.
private double cost = 10000.00;
private double taxRate = 17.5;
public double getPrice(double p)
{
return (p + (p * (taxRate/100)));
}
The above method will return 11750.0
I'm guessing that you have added the cost to the tax percentage rather than multiplied by it. i.e.
(p + (p + (taxRate/100)));
Which will return 20000.175, which is wrong. Replace the second + with a * and you should get the expected result.
Cheers
Martyn
|