Heres problem statement:
* The sum I pay must be round, i.e., divisible by 5.
* The tip must be between 5% and 10% of the final sum I pay, inclusive.
Clearly, sometimes there may be multiple "correct" ways of settling the bill.
Inputs:
* an int bill -- the amount I have to pay for the dinner
* an int cash -- the amount of money I have in my pocket
Write a function that computes how many different final sums satisfy the conditions above.
Heres the code I have so far:
public class TippingWaiters {
public int possiblePayments(int bill, int cash) {
int start=(int)(bill+.05*bill);
int end=(int)(bill+.1*bill);
if(start>cash)
start=cash;
if(end>cash)
end=cash;
int count=0;
for(int i=start;i<=end;++i)
if(i%5==0)
++count;
return count;
}
}
But I'm getting errors when compiling. For instance, with the inputs : 240 (bill) 279 (cash), the answer is 3 but the code gives me 2.
Can someone help
This post has been edited by messianic: 11 September 2009 - 06:46 PM

New Topic/Question
Reply




MultiQuote






|