Car Payment Calculator need help

Need help with car payment calculator almost done just need help with totalpaidforcar and interestpaid I am suppose to have a number for each year but it just comes up with a zero. Keep in mind I am a complete beginner.

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;


int main ()
{
double Payment, MonthlyInterestRate, NumberOfPayments, LoanAmount, ListPriceOfCar;
double DownPayment, AnnualInterestRate, PriceOfCar, SalesTax, SalesTaxRate, TotalPaidForCar,k;
double MonthlyPayment, MonthlyPayment2, MonthlyPayment3, MonthlyPayment4, MonthlyPayment5, MonthlyPayment6, NumberOfMonths, InterestPaid, years;

ListPriceOfCar = 10000;
DownPayment = 1000;
AnnualInterestRate = 0.03; 
SalesTaxRate = 0.0625;
MonthlyInterestRate = AnnualInterestRate / 12;
PriceOfCar = ListPriceOfCar - DownPayment;
SalesTax = PriceOfCar * SalesTaxRate;
LoanAmount = PriceOfCar + SalesTax;
TotalPaidForCar = MonthlyPayment * NumberOfMonths;
InterestPaid = TotalPaidForCar - LoanAmount;
NumberOfMonths = (12,24,36,48,60,72);
MonthlyPayment = (ListPriceOfCar * pow(MonthlyInterestRate + 1, 12) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 12) - 1);
MonthlyPayment2 =(ListPriceOfCar * pow(MonthlyInterestRate + 1, 24) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 24) - 1);
MonthlyPayment3 =(ListPriceOfCar * pow(MonthlyInterestRate + 1, 36) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 36) - 1);
MonthlyPayment4 =(ListPriceOfCar * pow(MonthlyInterestRate + 1, 48) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 48) - 1);
MonthlyPayment5 =(ListPriceOfCar * pow(MonthlyInterestRate + 1, 60) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 60) - 1);
MonthlyPayment6 =(ListPriceOfCar * pow(MonthlyInterestRate + 1, 72) * MonthlyInterestRate) / (pow(MonthlyInterestRate + 1, 72) - 1);






cout << "The list price of the car $";
cin >> ListPriceOfCar;
cout << "The Down payment $";
cin >> DownPayment;
cout <<"The Annual Interest Rate $";
cin >> AnnualInterestRate;


cout << endl;
cout << endl;


 

 

cout << "List Price Of Car - " << ListPriceOfCar << endl;
cout << endl;
cout << "Down Payment - " << DownPayment << endl;
cout << endl;
cout << "Sales Tax - " << SalesTax << endl;
cout << endl;
cout << "Loan Amount - " << LoanAmount << endl;
cout << endl;
cout << "Interest Rate - " << AnnualInterestRate << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;

cout <<"Loan Term"<<setw(10)<<"12"<<setw(10)<<"24"<<setw(10)<<"36"<<setw(10)<<"48"<<setw(10)<<"60"<<setw(10)<<"72"<<endl<<endl;
cout <<"Payment"<<setw(15)<<MonthlyPayment<<setw(10)<<MonthlyPayment2<<setw(10)<<MonthlyPayment3<<setw(10)<<MonthlyPayment4<<setw(10)<<MonthlyPayment5<<setw(10)<<MonthlyPayment6<<endl;
cout <<"Total Paid"<<setw(15)<<TotalPaidForCar;
cout <<"Interest paid"<<setw(15)<<
 

 

system ("PAUSE");
return 0;
}
Last edited on
Hi,

The compiler tells where the problems are:

 In function 'int main()':
 23:22: warning: left operand of comma operator has no effect [-Wunused-value] 
23:25: warning: right operand of comma operator has no effect [-Wunused-value] 
23:28: warning: right operand of comma operator has no effect [-Wunused-value] 
23:31: warning: right operand of comma operator has no effect [-Wunused-value] 
23:34: warning: right operand of comma operator has no effect [-Wunused-value] 
9:8: warning: unused variable 'Payment' [-Wunused-variable] 
9:38: warning: unused variable 'NumberOfPayments' [-Wunused-variable] 
10:93: warning: unused variable 'k' [-Wunused-variable] 
11:125: warning: variable 'InterestPaid' set but not used [-Wunused-but-set-variable] 
11:139: warning: unused variable 'years' [-Wunused-variable] 
21:50: warning: 'MonthlyPayment' is used uninitialized in this function [-Wuninitialized] 
21:50: warning: 'NumberOfMonths' is used uninitialized in this function [-Wuninitialized]


uninitialized variables are one of the biggest source of errors.

Code is executed sequentially, so there is no point in asking for the values of variables (at the end) after you have used them to do calculations.

You need to make use of arrays or better a std::vector. Use some logic to accumulate the month numbers, rather than attempting to hard code values for them.

Have a read of the tutorial top left of this page.

Some style pointers:

Declare variables one per line.

Delay the declaration until you have a sensible value to assign to it.

There is no need to have massive cout statements that are 2 or 3 screens wide, they can be built up in stages with multiple cout statements.

Topic archived. No new replies allowed.