Program that computes amount of months to repay a loan

My program is correctly outputting the correct amount of months to repay a given loan amount. Could someone help me with the math part of the solution? I'm trying to use L = $1000, MP = $25, I = 7.2%

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  #include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	double L, I, MP;
	int M;
	int counter;
	
	cout << fixed << showpoint << setprecision(2);

	cout << "Enter loan amount: ";
	cin >> L;
	cout << endl;
		
	cout << "Enter amount of monthly payment: ";
	cin >> MP;
	cout << endl;

	cout << "Enter interest rate: ";
	cin >> I;
	cout << endl;

	M = 0;
	I = I / 100;

	while (M > 0)

		MP = (L - I)-(I / 12) - MP;
		M = MP / 12;	

	cout << "The total number of months to repay is: " << M
	<< endl;
		
	
	return 0;
Last edited on
Are there a certain amount of months that you're looking to pay it in? As it sits, your code will get here

1
2
3
4
while (M > 0)

		MP = (L - I)-(I / 12) - MP;
		M = MP / 12;


Since M = 0 when you hit that portion, it will read as false (not true) and continue without going into that code.

Are you wanting to see payments over a series of months, or do you want to just enter a loan amount, interest, and payment and have it paid off in one, two, three, etc... set amount of years. (Is this how the gov see's it? Food? That's a luxury right?)
I may have not been clear in writing my question, but the purpose of my program is suppose to be to enter the loan, interest, and monthly payment amounts and to compute the number of months it will take to repay the loan at the given interest rate and monthly payment.
The problem may be that the equations are not right
Topic archived. No new replies allowed.