Difficult calculation problem.

I am trying to calculate the amount of time it will take to repay a loan given an initial loan amount, annual interest rate, and desired monthly payment. The answer is the same no matter what the input is, a big ugly negative number.

I am using this formula:http://oakroadsystems.com/math/mypics/loaneq3.gif

INPUT:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <cmath>
#include "header.h"
using namespace std;

void input (float & loanAmount, float & yearlyRate , float & monthlyPayment, float & monthlyRate)

{  
     
   cout << "Please enter the loan amount, the yearly interest rate, the desired payment." << endl;
   cin >> loanAmount >> yearlyRate >> monthlyPayment >> desiredYears;
   
   monthlyRate = ((yearlyRate / 12.0) * .01);
                    
} 


CALCULATE:
1
2
3
4
5
6
7
8
9
10
11
#include "header.h"
#include <cmath>

void calculate (float loanAmount, float yearlyRate, float monthlyPayment, float monthlyRate, int & months_to_repay) 

    
{    
    
    months_to_repay = -log10(1 - ((monthlyRate * loanAmount) / monthlyPayment) / log10(1 + monthlyRate));    
    
}
Last edited on
Can you re-post the formula,because that link doesn't open for me.I think the problem might be in formula.Maybe you didn't write it correctly.
Link is broken.
Aside from that, I don't see any call to calculate or input anywhere.
On top of that i don't see a main function.
Topic archived. No new replies allowed.