Help with FOR LOOPS

Hey all I'm having trouble with for loops. I need to calculate monthly balance and interest paid on a balloon mortgage and am having trouble with the calculations. An example of what the program should look like:

Enter Mortgage: 100000
Enter Interest Rate: 5
Enter Payment Amount: 1000
Enter Number of Years for Loan: 5

Month Balance Payment Interest
1 100000.00 1000.00 412.50
2 99412.50 1000.00 410.05
|
|
|
60 60797.27 1000.00 249.16

Balloon Payment: 60046.43


Here is my code so far:

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
 
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    double mortgage, interest, payment, years, monthlyInterest, monthlyBalance, numPayments;
    int counter;
     
    cout << "Please enter a mortgage amount: ";
    cin >> mortgage;
    cout << "Please enter an annual interest rate: ";
    cin >> interest;
    cout << "Please enter a payment amount: ";
    cin >> payment;
    cout << "Please enter number of years for the loan: ";
    cin >> years;
     
    monthlyInterest = ((mortgage - payment) * interest / 12);
    monthlyBalance = ((mortgage - payment) + monthlyInterest);
    numPayments = (years * 12);
     
    cout << "Month" << '\t' << "Balance" << '\t' << '\t' << "Payment" << '\t'<< '\t' << "Interest" << endl;
     
    for (counter = 1; counter <= numPayments; counter++)
    {
    cout << counter << '\t' << setiosflags(ios::fixed) << setprecision(2) << monthlyBalance << '\t' << payment << '\t' << '\t' << setiosflags(ios::fixed) << setprecision(2) << monthlyInterest << endl;
    }
     
     
    }
Last edited on
So.... what's the problem? Does this code not do what you want or something?
What was your error? Ok nevermind, put your equations inside the loop.
Last edited on
When I try to run the code I keep getting the same value for balance and interest and am not sure what I am doing wrong.
^^
Thanks for the help but now when I put the equations inside the loop it only brings up the table ID's and nothing else
you set interest to the value read in and at no point in the code do you try and change it. You don't have a variable called balance.
so your counter doesn't really do anything. What is it your trying to increment? Number of years I suppose
hmm unfortunately I am terrible at programming and still learning the basics so I'm not quite sure what you mean.
Well are you sure you're equations are right, Because the only thing that's ever going to change is the variable counter (or NumPayments) but nowhere in your other variables does the value of the counter affect them.
Last edited on
I was told by an assistant professor that my calculations seemed correct but now I may be starting to second guess that which is why I came here lol. The more I try to change things around the more I get confused.
Just looking at your logic (so don't worry about programming for a second), does what your asking even make much sense?

"Please enter a mortgage amount: " <--

"Please enter an annual interest rate: "

"Please enter a payment amount: " <--
Is this how much the person will pay each year?

"Please enter number of years for the loan: " <--

Should at least one of the three things I marked not be calculated by the program? If I say I want a mortgage of $500000 and want a payment amount of $100 for 3 years, is that not just daft?

Either the number of years, or the the payment amount should be calculated by your software.

by the way maybe a loop like this is more what you're trying to accomplish, but I can't really tell from your code

 
for(numberpayments=1;numberpayments<=(years*5);numberpayments++)
Last edited on
Topic archived. No new replies allowed.