Financial Application (Comparing loans with various interest rates)

I have some problem with below, I hope that i can get some hint
Write a program that lets the user enter the loan amount and loan period

Last edited on
So what is your question? Where are you stuck?
Also try and use code tags http://www.cplusplus.com/articles/jEywvCM9/
when posting, more people will be willing to help!
Made some changes so at least you don't have infinite loops running.

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
47
#include <iostream>
#include <cmath>
#include<iomanip>
using namespace std;

int main()
{
    double loanAmount;
    int numberOfYears;
    double annualInterestRate = 5;
    double monthlyInterestRate;
    double monthlyPayment;
    double totalPayment;

    // Enter loan amount
    cout << "Loan Amount: ";
    cin >> loanAmount;

    // Enter number of years
    cout << "Number of Years: ";
    cin >> numberOfYears;

    // Obtain monthly interest rate
    monthlyInterestRate = annualInterestRate / 12;

    for (double i = 5; i <= 8; i += 0.125)  // i has to be a float
    {
        for(double j = 1; j <= numberOfYears;j++)
        {
            monthlyPayment = monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / pow(1 + monthlyInterestRate, numberOfYears * 12));
            cout << setw(3) << j;
            cout << "\n";
        }
    }

    for (double x = numberOfYears; x < totalPayment; x++ )
    {
        totalPayment = monthlyPayment * numberOfYears * 12;
        cout << setw(3) << x;
        cout << "\n";
    }

    // Display results
    cout << "Interest Rate " << annualInterestRate << "% " << "\nMonthly Payment " << monthlyPayment << "\nTotal Payment " << totalPayment << endl;

    return 0;
}

Topic archived. No new replies allowed.