I am trying to get the number of months on one side to pay a car loan off and then the other side to have a decrease in the money owned. I have been staring at this thing for about 2 hours and i dont understand why it won't subtract the monthly total per month. Any help would be greatly appreciated.

Month    Money Owed
-----------------------

0               9775
1               9774
2               9773
3               9772
4               9771
5               9770
6               9769
7               9768
8               9767
9               9766
10              9765

Code:

int interest, principle, moneyowed, payment, monthly;

        //these four lines are for the first month
        cout <<"I have been loaned $10,000.00 for my vehicle." << endl;
        moneyowed=10000.00;
        interest =(moneyowed * .0075); //annual interest rate of 9% but .75% per month
        payment = 300; //monthly payments of $300.00
        principle=(payment-interest);
        monthly=(moneyowed-principle);

cout <<"Month \t Money Owed" << endl;
cout <<"-----------------------"<<endl;
int num=0;
while (num<=10)
                {
                cout <<num << "\t\t" << (monthly--) << endl;
                num++;
                }
        return 0;
}

Recommended Answers

All 6 Replies

I'm bad with math related to business, hope i'm right about this.

By answering: "why it won't subtract the monthly total per month."

You'll see that you will want the subtract the principle each month. So by right this subtraction should be included inside the loop.

monthly-- : only decrements the current value by 1.
Hope you can see the next steps. Cheers

you have to update the moneyowed within the loop:
and, you don't need the monthly variable.

#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

int main()
{
	double interest, principle, moneyowed, payment;
	cout <<"I have been loaned $10,000.00 for my vehicle." << endl;
	moneyowed = 10000.00;
	payment = 300.00;	 //monthly payments of $300.00
	interest =(moneyowed * .0075); //annual interest rate of 9% but .75% per month
        principle=(payment-interest);
	
	cout <<"Month \t Money Owed" << endl;
	cout <<"-----------------------"<<endl;

	int num = 1; // 1 for the first month, 2 for the second, etc...
	while (num <= 10) // for 10 months, loop and decrement the money you owe
	{

		moneyowed=(moneyowed-principle); // update the moneyowed and display it
		cout<<num<<"\t\t"<<moneyowed<<endl;
		num++;
	
	}
	return 0;
}

hope this helps

So I took your guys' great advice but I'm still very much a c++ newb and don't understand why the moneyowed isn't producing the results my formulas indicates.. any suggestions?

#include <iostream>
using namespace std;
int main()

{
float interest, principle, moneyowed, num;

        //these four lines are for the first month
        cout <<"I have been loaned $10,000.00 for my vehicle." << endl;
        cout <<"Month \t Money Owed" << endl;
        cout <<"-----------------------"<<endl;
        num=0;
        while (num<=40)
        {
                interest-= moneyowed * .0075;
                principle+=(300-interest);
                moneyowed=(10000-(interest+principle));
                cout << num << "\t" << moneyowed << endl;
                num++;
        }
        return 0;
}
I have been loaned $10,000.00 for my vehicle.
Month    Money Owed
-----------------------
0       9700
1       9400
2       9027.25
3       8584
4       8073.05
5       7497.71
6       6861.83
7       6169.71
8       5426.14
9       4636.28
10      3805.74
11      2940.42
12      2046.55
13      1130.64
14      199.373
15      -740.372
16      -1681.61
17      -2617.3
18      -3540.38
19      -4443.82
20      -5320.71
21      -6164.28
22      -6967.94
23      -7725.36
24      -8430.53
25      -9077.76
26      -9661.75
27      -10177.7
28      -10621.1
29      -10988.2
30      -11275.7
31      -11480.7
32      -11601.2
33      -11635.6
34      -11583
35      -11443.1
36      -11216.3
37      -10903.7
38      -10507
39      -10028.5
40      -9471.19

go step by step debug yourself. You can put cout for your interest/principle/moneyowned in every loop. So you can find out which is the error.

I'm not sure what you mean by "results my formulas indicates". What exactly is your formula? I suggest doing all of the calculations with pen and paper, confirming what exactly you want to do, and then developing the algorithm. coding will come easier once you have that down.

Can you copy paste your code on here??? And once you do that can you highlight it and click the CODE button so it puts it into the code??? I can try and help you out if you do that. I took programming one and it was in C++. I had to make a yahtzee game so I think I can help you out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.