Need Help with a for loop

So for my code, I need to display a 12-month table. There needs to be 3 things on the table: the amount of interest that is needed to be paid, the principal that needs to be paid, and the balance. The math is all there and it's definitely right, but I am stuck at getting the table to display each month separately. My loop right now will display the first month over and over. Thanks so much for your help! (:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
  void monthly(float year, float total, float rate, float loan){
	float month = year * 12;
	float interest;
	float principal;
	float balance;
	rate = rate / 100 / 12;
	for (int i = 0; i < month; i++){
		
		interest = loan * rate;
		principal = total - interest;
		balance = loan - principal;
	
		cout << i + 1 << "\t" << interest << "\t" << principal << "\t" << balance << endl;
	}
how do you intend to represent a month?

ints? array? class? etc...
Are you sure that math is right? Since loan and rate don't change inside the loop, line 9 always sets interest to the same thing. So interest never changes.

Since interest and total never change, principal never changes (line 10)

Since loan and principal never change, balance never changes (line 11).

Also, what is the difference between the total argument and the loan argument?
Basing the info off of you, dhayden, would it make sense to make a temp variable to store the data that I get from doing the first round of the loop and basing the next month's off of that somehow? If so, how would I go about doing that?

Total is the amount for the total monthly payment. So if i inputted $5000 for the loan, 12.9% for the rate, and 1 for year, the total monthly payment would be 446.35. I will also show you what the table output is as of right now so maybe you can have a better image.

Month Interest Principal Balance
----------------------------------------------------------
1 53.75 392.60 4607.40
2 53.75 392.60 4607.40
3 53.75 392.60 4607.40
4 53.75 392.60 4607.40
5 53.75 392.60 4607.40
6 53.75 392.60 4607.40
7 53.75 392.60 4607.40
8 53.75 392.60 4607.40
9 53.75 392.60 4607.40
10 53.75 392.60 4607.40
11 53.75 392.60 4607.40
12 53.75 392.60 4607.40

Yes. The first thing you need to do is compute the monthly payment. Then at each month:
1
2
3
interest = balance * rate;
principal = payment - interest;
balance -= principal;
Topic archived. No new replies allowed.