JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat  | Threaded  | Tree
Previous Thread  |  Next Thread
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<iostream>
#include<cmath>
using 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<term*12;i++){

balance = balance-monthlyPayment;
if(balance><=0.0){break;}
balance = ceil(balance*(1+ir));
}
if(balance<=0.0){
hi=monthlyPayment;
}else{
lo=monthlyPayment+1;
}
}
return lo;
}
};
Subject Author Date
Mortgage - problem with the last system test whitesoulxxxx Oct 7, 2017 at 11:12 AM EDT
RSS