anyone help me with this

When you borrow money to BUY A HOUSE or a car, or for some other purpose, you repay the loan by making periodic payments over a certain time. Of course the lending company will charge interest on the loan. Every periodic payment consists of the interest on the loan and the payment toward the principal amount. To be specific, suppose that you borrow $1000 at the interest rate of 7.2% per year and the payments are monthly. Suppose that your monthly payment is $25. The interest rate per month is 7.2/12 = 0.6%. The first month’s interest on $1000 is 1000 * 0.006 = 6. Because the payment is $25 and the interest for the first month is $6, the payment toward the principal amount is 25 – 6 = 19. This means that after making the first payment, the loan amount is 1000 – 19 = 981. For the second payment, the interest is calculated on $981. So the interest for the second month is 981* 0.006 = 5.886, that is, approximately $5.89. This implies that the payment towards the principle is 25 – 5.89 = 19.11, and the remaining balance after the second payment is 981 – 19.11 = 961.89. This process is repeated until the loan is paid. Write a program that accepts as input, the loan amount, the interest rate per year, and the monthly payment. (Enter the interest rate as a percentage. For example, if the interest rate is 7.2 % per year, then enter 7.2). The program then outputs the number of months it would take to repay the loan. (Note that if the monthly payment is less than the first month’s interest, then after each payment, the loan amount will increase. In this case, the program must warn the borrower that the monthly payment is too low and with this monthly payment the loan amount could not be repaid.)



#include <iostream>
using namespace std;
void main()
{
double loan_amount, yearly_intrest, monthly_payment;
cout << "enter loan amount" << endl;
cin >> loan_amount;
cout << "enter yearly intrest " << endl;
cin >> yearly_intrest;
cout << "enter monthly payment" << endl;
cin >> monthly_payment;

double monthly_intrest = yearly_intrest / 12;
cout << "loan will be paid on" << (loan_amount / (monthly_intrest - (loan_amount*monthly_intrest))) << " month " << endl;
if (monthly_payment < monthly_intrest)
{
cout << "warning payment is low";
}
}
is this right ??
No, as per your specs you need the program to loop until the loan is paid off and a counter to check the amount of months it takes.
closed account (48T7M4Gy)
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
39
40
41
42
43
44
45
46
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    double loan_amount = 0, yearly_interest_rate = 0, monthly_payment = 0, nett_payment = 0;
    double monthly_interest_rate = 0, interest = 0;
    double current_balance = 0;
    
    int month_no = 0;
    
    // LOAN AMOUNT
    cout << "enter loan amount" << endl;
    cin >> loan_amount;
    
    // YEARLY INTEREST
    cout << "enter yearly interest " << endl;
    cin >> yearly_interest_rate;
    
    // MONTHLY PAYMENT
    cout << "enter monthly payment" << endl;
    cin >> monthly_payment;
    
    monthly_interest_rate = yearly_interest_rate / 12;
    current_balance = loan_amount;
    
    while(current_balance >= 0)
    {
        month_no++;
        
        interest = current_balance * monthly_interest_rate;
        nett_payment = monthly_payment - interest;
        current_balance = current_balance - nett_payment;
        
        cout
        << setw(10) << month_no
        << setw(10) << fixed << setprecision(2)<< interest
        << setw(10) << nett_payment
        << setw(10) << current_balance
        << endl;
    }
    
    return 0;
}


enter loan amount
1000
enter yearly interest
.072
enter monthly payment
25
1 6 19 981
2 5.886 19.114 961.886
3 5.77132 19.2287 942.657
4 5.65594 19.3441 923.313
5 5.53988 19.4601 903.853
6 5.42312 19.5769 884.276
7 5.30566 19.6943 864.582
8 5.18749 19.8125 844.769
9 5.06862 19.9314 824.838
10 4.94903 20.051 804.787
11 4.82872 20.1713 784.616
12 4.70769 20.2923 764.323
13 4.58594 20.4141 743.909
14 4.46346 20.5365 723.373
15 4.34024 20.6598 702.713
16 4.21628 20.7837 681.929
17 4.09158 20.9084 661.021
18 3.96613 21.0339 639.987
19 3.83992 21.1601 618.827
20 3.71296 21.287 597.54
21 3.58524 21.4148 576.125
22 3.45675 21.5432 554.582
23 3.32749 21.6725 532.909
24 3.19746 21.8025 511.107
25 3.06664 21.9334 489.174
26 2.93504 22.065 467.109
27 2.80265 22.1973 444.911
28 2.66947 22.3305 422.581
29 2.53548 22.4645 400.116
30 2.4007 22.5993 377.517
31 2.2651 22.7349 354.782
32 2.12869 22.8713 331.911
33 1.99146 23.0085 308.902
34 1.85341 23.1466 285.756
35 1.71453 23.2855 262.47
36 1.57482 23.4252 239.045
37 1.43427 23.5657 215.479
38 1.29288 23.7071 191.772
39 1.15063 23.8494 167.923
40 1.00754 23.9925 143.93
41 0.863581 24.1364 119.794
42 0.718763 24.2812 95.5126
43 0.573075 24.4269 71.0856
44 0.426514 24.5735 46.5122
45 0.279073 24.7209 21.7912
46 0.130747 24.8693 -3.07802
Program ended with exit code: 0
Last edited on
thank you !
Topic archived. No new replies allowed.