For loop from array data

I'm having a bit of an issue with a piece of code. The program I'm writing is meant to gather data through user input, calculate estimated payment information, and output the data as monthly payment options in increments of 12 months.

The program compiles without, but only the first value correct. I feel as if I'm overlooking something small and need another set of eyes on this. I think my problem lies somewhere in the last two functions.



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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
  #include <iostream>
#include <cmath>
#include <iomanip>


using namespace std;

float getPrice();
float getTradeIn(float);
float getDownPayment(float, float);
float getInterestRate();
float calcMonPayment(float, float, int[]);
void displayLoanSchedule(float, float, float, float, float, int[],float[]);


int main()
{
	int noMonths[] = { 12, 24, 36, 48, 60 };
	float monPayment[5] = { 12, 24, 36, 48, 60 };
	

	float price, tradeIn, downPayment, annualIntRate;

	cout << "************************************************************************************************************";
	cout << endl;
	cout << "Welcome!This program will assist you in choosing the best payment option here at Honest Dave's." << endl;
	cout << "Please have the price of your new vehicle, trade-in of your of old vehicle, and your down payment amount ready for input.";
	cout << endl;
	cout << "************************************************************************************************************";

	

	price = getPrice();
	tradeIn = getTradeIn(price);
	downPayment = getDownPayment(price, tradeIn);
	annualIntRate = getInterestRate();
    float annualIntPercent = annualIntRate * 100.0;
	
	float loanAmt = price - downPayment - tradeIn;
	float monIntRate = annualIntRate / 12.0;

	*monPayment=calcMonPayment(loanAmt, monIntRate, noMonths);

	
	displayLoanSchedule(price, tradeIn, downPayment, loanAmt,annualIntPercent, noMonths, monPayment);
	

	return 0;
}
float getPrice()
{
	float price;

	do
	{
		cout << endl;
		cout << "What is the price of the vehicle you wish to purchase ?" << endl;
		cout << endl;
		cin >> price;
		cout << endl;

		if (price < 75.00 || price > 48500.00)
			cout << "Your amount is invalid. Please enter a dollar amount greater than $75.00 and less than $48,500.00.";
		cout << endl;

	} while (price < 75.00 || price > 48500.00);

	return price;
}
float getTradeIn(float price)
{
	float tradeIn;

	do
	{
		cout << endl;
		cout << " Please input the value of your trade in:";
		cout << endl;
		cin >> tradeIn;
		cout << endl;

		if (tradeIn < 0 || tradeIn>price)
			cout << " Please enter a price greater than $0 and less than purchase price.";
		cout << endl;

	} while (tradeIn <0 || tradeIn>price);

	return tradeIn;
}
float getDownPayment(float price, float tradeIn)
{
	float downPayment;
	do
	{
		cout << endl;
		cout << "Please enter your down payment amount" << endl;
		cin >> downPayment;
		cout << endl;

		if (downPayment < 0 || downPayment > price - tradeIn)
			cout << "Please enter a value between $0 and the price of your new vehicle." << endl;
		cout << endl;

	} while (downPayment < 0 || downPayment >= price - tradeIn);

	return downPayment;
}
float getInterestRate()
{
	float annualIntRate;
	do
	{
		cout << "Please enter the current interest rate: " << endl;
		cout << "Ex: 15 percent = 0.15" << endl;
		cin >> annualIntRate;
		cout << endl;

		if (annualIntRate < 0 || annualIntRate > 0.30)
			cout << "Your annual interest rate should be greater than 0 and less that 0.19.";
		cout << endl;

	} while (annualIntRate < 0 || annualIntRate > 0.30);


	return annualIntRate;
}
float calcMonPayment(float loanAmt, float monIntRate, int* noMonths)
{
	float monPayment[]={12,24,36,48,60};

	for (int i; i<5; i++)
	{
		monPayment[0]= (loanAmt * monIntRate) / (1.0 - (pow)(1 + monIntRate, -1 * (noMonths[i])));
		
		
	}
	
	return *monPayment;
}
void displayLoanSchedule(float price, float tradeIn, float downPayment, float loanAmt, float annualIntPercent, int noMonths[],float *monPayment)
{

	cout << endl;
	cout << endl;
	cout << "     Honest Dave's Used Cars     ";
	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 << 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";

	cout << endl;

	
	for (int i ; i <5; i++)
	{
		cout << noMonths[i] << " Months" << setw(17) << fixed << setprecision(2) << "$ " << monPayment[i] << endl;

	}
	cout << "" << endl;
}
Perhaps you're either ignoring or didn't see some important messages your compiler should be giving you??

In function 'float calcMonPayment(float, float, int*)':
131:11: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
In function 'void displayLoanSchedule(float, float, float, float, float, int*, float*)':
161:11: warning: 'i' may be used uninitialized in this function [-Wmaybe-uninitialized]
Honestly, I'm not seeing those errors on my side. I'll look into it. To replicate, how do you run this? From here?
Yes from here. I press the little gear icon to the right of the code block.

If you're not getting the warnings you really need to see about increasing your compiler warning levels.

I have all three warning levels checked. I'm still not seeing them.
Not seeing them where?

If you're talking about the online compiler (the gear) then you need to stop the program and click on the compilation tab.

I'm not seeing them in my compiler nor the online compiler.
Topic archived. No new replies allowed.