JOIN
 Select a Forum     Round Tables New Member Discussions News Discussions Algorithm Matches Marathon Matches NASA Tournament Lab TopCoder Cookbook High School Matches Sponsor Discussions Development Forums Design Forums Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings View: Flat (oldest first)  | Threaded  | Tree Previous Thread  |  Next Thread Forums Tutorial Discussions Binary Search tutorial Mortgage - problem with the last system test
 Mortgage - problem with the last system test | Reply Hi, I am trying to solve the Mortgage problem mentioned in this tutorial. This code passess every system test except the last one, where it returnes a value "1976284584" instead of "1976284585". Can you help me with solving this problem?#include#includeusing namespace std;class Mortgage{ public: int monthlyPayment(int loan, int interest, int term){ long double lo = 0.0; long double hi = 2000000000.0; long double monthlyPayment; long double balance; long double ir = interest/10.0/12.0/100.0; while((hi-lo)/hi>1e-9){ balance = loan; monthlyPayment = lo+(hi-lo)/2.0; for(int i=0;i<=0.0){break;} balance = ceil(balance*(1+ir)); } if(balance<=0.0){ hi=monthlyPayment; }else{ lo=monthlyPayment+1; } } return lo; }};
 Forums Tutorial Discussions Binary Search tutorial Mortgage - problem with the last system test Previous Thread  |  Next Thread