I am so close! ( i think....)

Hey everyone! I am working on a project and I am sooo close, or so I think, to being done. I am having trouble with one section of this program. when it runs, it displays 4 different car payment amounts, but i don't get 4 different ones. I am getting the same payment amount for all 4 options.

I think my problem is in line 112-118...


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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>              
#include <cmath>                 
#include <iomanip>                   
	 
using namespace std;
	 
//Prototypes
float getPrice();
float getTradeIn(float);
float getDownPayment(float, float);
float getInterestRate();
float calcMonPayment(float, float);
void displayLoanSchedule(float, float, float, float, float, float);
	 
	 
int main()
{
	int noMonths[4] = {24, 36, 48, 60};
	float price;
	float downPayment;
	float tradeIn;     
	float annualIntRate;
	price = getPrice();
	tradeIn = getTradeIn(price);
	downPayment = getDownPayment (price, tradeIn);
	annualIntRate = getInterestRate();
	float loanAmt = price - downPayment - tradeIn;      
	float annualIntPercent = annualIntRate * 100.0 ;
	float monIntRate = annualIntRate / 12.0;      
	float monPayment;
	monPayment = calcMonPayment(loanAmt, monIntRate);
	         
	displayLoanSchedule(price, tradeIn, downPayment, loanAmt, annualIntPercent, monPayment);
	 
	//Press any key to continue
	system("pause");
	return 0 ;
}
	 
	//Price Function
	float getPrice()
{
	float price;
	 
	do
{
	cout << "Please input the the price of the car:   ";
    cin >> price;
	         
	if (price < 50.00 || price > 50000.00)           
	cout << "Price must be between $50.00 and $50,000.00, please retry" << endl;       
}
	while (price < 50.00 || price > 50000.00);
	return price;
}
	 
	//Trade-In Function
	float getTradeIn(float price)
{  
	float tradeIn;
	     
	do
{
	     
	cout << "Please input the price of your trade in:   ";
	cin >> tradeIn;
	         
	if (tradeIn < 0.0||tradeIn >= price)         
	cout << "Price must be between 0.0 and the price of the car, please retry" << endl;    
}
	while (tradeIn < 0.0 || tradeIn >= price);
	return tradeIn;
}
	 
	 
	//Downpayment Function
	float getDownPayment (float price, float tradeIn)
{  
	float downPayment;
	     
	do
{
	cout << "Please input the price of your down payment (enter 0 in none):   ";
	cin >> downPayment;
	         
	if (downPayment < 0.0||downPayment >= price - tradeIn)           
	cout << "Price should be between 0 and the price of the car minus trade-in amount" << endl;    
}
	while (downPayment < 0.0 || downPayment >= price - tradeIn);
	return downPayment;
}
	 
	 
	//Interest Rate Function
	float getInterestRate()
{
	float annualIntRate;
	 
	do
{
	cout << "Please input the annual interest rate as a decimal." << endl << "Example: 15 percent would be .015:   ";
	cin >> annualIntRate;
	         
	if (annualIntRate <= 0.0 || annualIntRate > 0.50)        
	cout << "Annual interest rate should be greater than 0 and less than 0.5" << endl;     
}
	while (annualIntRate <= 0.0 || annualIntRate > 0.50);
	return annualIntRate;
}
	 
	//Monthly Payment Function
	float calcMonPayment( float loanAmt, float monIntRate)
{
	float monPayment;
	int noMonths[] = {24, 36, 48, 60};
	     
	monPayment = (loanAmt * monIntRate) / (1.0 - (pow)(1+monIntRate, -1 * (noMonths[0])));
	return  monPayment;
}
	 
	 
	//Display Output
	void displayLoanSchedule(float price, float tradeIn, float downPayment, float loanAmt, float annualIntPercent,  float monPayment )
{
	system("cls");

	int noMonths[] = {24, 36, 48, 60 };
	cout << "                  Welcome To Honest Dave's Used Cars";
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "" << endl;
	cout << "Vehicle Price: " << setw(15) << fixed << setprecision(2) << "$" << price << endl;
	cout << "Trade In Value: " << setw(14) << fixed << setprecision(2) << "$" << tradeIn << endl;
	cout << "Down Payment: " << setw(16) << fixed << setprecision(2) << "$" << downPayment << endl;
	cout << "" << endl;
	cout << setw(38) << "______________" << endl;
	cout << "" << endl;
	cout << "Loan Amount: " << setw(17) << fixed << setprecision(2) << "$" << loanAmt << endl;
	cout << "" << endl;
	cout << "Annual Interest Rate: " << setw(11) << fixed << setprecision(1) << annualIntPercent << "%" << endl;
	cout << "" << endl;
	cout << "Monthly Payment Options: " << endl;
	cout << "" << endl;
	     
	for (int n=0; n<4; n++)
{
	cout << "     " << noMonths[n] << " Months" << setw(17) << fixed << setprecision(2) << "$ " << monPayment << endl;
}
	     
	cout << "" << endl;
}
Looking at lines 112-118 I'd say you're probably right. You should probably pass in the number of months you're calculating the payment for and substitute the value in your calculation accordingly. As it is you're just using the first value in your noMonths array.
You just needed to calculate the four different values and save them.

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>              
#include <cmath>                 
#include <iomanip>                   
	 
using namespace std;
	 
//Prototypes
float getPrice();
float getTradeIn(float);
float getDownPayment(float, float);
float getInterestRate();
void calcMonPayment(float, float,int [],float []);
void displayLoanSchedule(float, float, float, float, float, int[], float[]);

const int MonthOptions(4);	 
	 
int main() {
   int noMonths[MonthOptions] = {24, 36, 48, 60};
   float monPayment[MonthOptions] = {0};
   float price;
   float downPayment;
   float tradeIn;     
   float annualIntRate;
   price = getPrice();
   tradeIn = getTradeIn(price);
   downPayment = getDownPayment (price, tradeIn);
   annualIntRate = getInterestRate();
   float loanAmt = price - downPayment - tradeIn;      
   float annualIntPercent = annualIntRate * 100.0 ;
   float monIntRate = annualIntRate / 12.0;      
   calcMonPayment(loanAmt, monIntRate,noMonths, monPayment);
	         
   displayLoanSchedule(price, tradeIn, downPayment, loanAmt, 
                               annualIntPercent, noMonths,monPayment);
	 
   //Press any key to continue
   return 0 ;
}
	 
//Price Function
float getPrice() {
   float price;
   do {
     cout << "Please input the the price of the car:   ";
     cin >> price;
	         
     if (price < 50.00 || price > 50000.00)           
	cout << "Price must be between $50.00 and $50,000.00, please retry" << endl;       
   } while (price < 50.00 || price > 50000.00);
   return price;
}
	 
//Trade-In Function
float getTradeIn(float price) {  
   float tradeIn;
   do {
     cout << "Please input the price of your trade in:   ";
     cin >> tradeIn;
	         
     if (tradeIn < 0.0||tradeIn >= price)         
       cout << "Price must be between 0.0 and the price of the car, please retry" << endl;    
   } while (tradeIn < 0.0 || tradeIn >= price);
   return tradeIn;
}
	 
	 
//Downpayment Function
float getDownPayment (float price, float tradeIn) {  
   float downPayment;
   do {
     cout << "Please input the price of your down payment (enter 0 in none):   ";
     cin >> downPayment;
	         
     if (downPayment < 0.0||downPayment >= price - tradeIn)           
       cout << "Price should be between 0 and the price of the car minus trade-in amount" << endl;    
   } while (downPayment < 0.0 || downPayment >= price - tradeIn);
   return downPayment;
}
//Interest Rate Function
float getInterestRate() {
   float annualIntRate;
	 
   do {
     cout << "Please input the annual interest rate as a decimal." 
          << endl << "Example: 15 percent would be 0.15:   ";
     cin >> annualIntRate;
	         
     if (annualIntRate <= 0.0 || annualIntRate > 0.50)        
        cout << "Annual interest rate should be greater than 0 and less than 0.5" << endl;     
  } while (annualIntRate <= 0.0 || annualIntRate > 0.50);
  return annualIntRate;
}
	 
//Monthly Payment Function
void calcMonPayment( float loanAmt, float monIntRate,int *noMonths,float *monPayment) {
   for ( int i(0); i<MonthOptions;i++){     
      monPayment[i] = (loanAmt * monIntRate) / (1.0 - (pow)(1+monIntRate, -1 * (noMonths[i])));
   }
   return;
}
	 
//Display Output
void displayLoanSchedule(float price, float tradeIn, float downPayment, 
                  float loanAmt, float annualIntPercent,  int noMonths[], float monPayment[] )
{
   cout << "                  Welcome To Honest Dave's Used Cars";
   cout << "" << endl;
   cout << "" << endl;
   cout << "" << endl;
   cout << "" << endl;
   cout << "Vehicle Price: " << setw(15) << fixed << setprecision(2) << "$" << price << endl;
   cout << "Trade In Value: " << setw(14) << fixed << setprecision(2) << "$" << tradeIn << endl;
   cout << "Down Payment: " << setw(16) << fixed << setprecision(2) << "$" << downPayment << endl;
   cout << "" << endl;
   cout << setw(38) << "______________" << endl;
   cout << "" << endl;
   cout << "Loan Amount: " << setw(17) << fixed << setprecision(2) << "$" << loanAmt << endl;
   cout << "" << endl;
   cout << "Annual Interest Rate: " << setw(11) << fixed << setprecision(1) << annualIntPercent << "%" << endl;
   cout << "" << endl;
   cout << "Monthly Payment Options: " << endl;
   cout << "" << endl;
	        
   for (int n=0; n<MonthOptions; n++) {
      cout << "     " << noMonths[n] << " Months" 
           << setw(17) << fixed << setprecision(2) 
           << "$ " << monPayment[n] << endl;
   }
	     
   cout << "" << endl;
}
Please input the the price of the car:   15000
Please input the price of your trade in:   500
Please input the price of your down payment (enter 0 in none):   500
Please input the annual interest rate as a decimal.
Example: 15 percent would be 0.15:   0.08
                  Welcome To Honest Dave's Used Cars



Vehicle Price:               $15000.00
Trade In Value:              $500.00
Down Payment:                $500.00

                        ______________

Loan Amount:                 $14000.00

Annual Interest Rate:         8.0%

Monthly Payment Options: 

     24 Months               $ 633.18
     36 Months               $ 438.71
     48 Months               $ 341.78
     60 Months               $ 283.87

$


Topic archived. No new replies allowed.