Debugging Issues

Need help with debugging this program, it is resembling a car inventory. You can add cars, remove them. But this code seemed sort of legit, except its not working. =/ Any help is appreciated.




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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/************************************************
Array Sample
*************************************************/

#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

//******* Global Parallel Arrays *********
int carArraySize = 5;

string carMakeArray[carArraySize];
string carModelArray[carArraySize];
int carYearArray[carArraySize];
double carPriceArray[carArraySize];

//******* Function Prototypes ***********
void initArrays();
void displayArrays();
void addToArrays();
void removeFromArrays(int);

int main()
{
	int choice = 0;
	int arraySubscript = 0;

	initArrays();

	do
	{
		system("cls");
		displayArrays();
		cout << endl << endl;
		cout << "==== Car Inventory Options ====" << endl << endl;
		cout << "1. Add to Inventory" << endl;
		cout << "2. Remove from Inventory" << endl;
		cout << "3. End Program" << endl << endl;
		cout << "Please make a selection: ";
		cin >> choice;

		switch(choice)
		{
		case 1:
			addToArrays();
			break;
		case 2:
			system("cls");
			displayArrays();

			cout << endl << endl;
			cout << "Please enter the Index number of the car to remove: ";
			cin >> arraySubscript;
			
			removeFromArrays();
			break;
		case 3:
			return 0;
		default:
			cout << "Invalid Choice!" << endl;
			system("pause");
		}
	}while(true);

}

/**********************************************
Function: initArrays
Input:
Output:

Description:
Initializes the global parallel arrays
**********************************************/

void initArrays()
{
	for(int i = 0; i < carArraySize; i++)
	{
		carMakeArray[i] = "";
        carModelArray[i] = "";
		carYearArray[i] = 0;
		carPriceArray[i] = 0.0;
	}
	return;
}

/**********************************************
Function: displayArrays
Input:
Output:

Description:
Displays the global parallel arrays and allows basic operations.
**********************************************/

void displayArrays()
{
	system("cls");
	cout << "              ================= Car Inventory ====================" << endl << endl;
	cout << " Index     Year        Make                    Model                    Price" << endl;
	cout << "-----------------------------------------------------------------------------" << endl;
		
	for(int i = 0; i < carArraySize; i++)
	{
		if(carMakeArray[i] == "")
			cout << " " << i << ". " << "\t" << carYearArray[i] << "\t" << carMakeArray[i] << "\t" << carModelArray[i] << "\t" << setw(10) << carPriceArray[10] << endl;
	}

	return;
}

/**********************************************
Function: addToArrays
Input:
Output:

Description:
Allows additions to the global parallel arrays
**********************************************/

void addToArrays()
{
	
	string carMakeArray[carArraySize];
	string carModelArray[carArraySize];
	int carYearArray[carArraySize];
	double carPriceArray[carArraySize];
	
	system("cls");

	for(int i = 0; i < carArraySize; i++)
	{
		if(carMakeArray[i] == "")
		{
			cout << "==== Add to Car Inventory ====" << endl << endl;
			cout << "Car Year: ";
			cin >> carYearArray[i];
			cout << "Car Make: ";
			cin >> carMakeArray[i];
			cout << "Car Model: ";
			cin >> carModelArray[i];
			cout << "Car Price: ";
			cin >> carPriceArray[i];
			return;
		}
		else
		{
			cout << "Not Enough Array Space!" << endl;
			system("pause");
			return;
		
	}
}

/**********************************************
Function: removeFromArrays
Input:
Output:

Description:
Allows removal from the global parallel arrays.
**********************************************/

void removeFromArrays(int subscriptFromMain)
{
	carMakeArray[subscriptFromMain] = "";
    carModelArray[subscriptFromMain] = "";
	carYearArray[subscriptFromMain] = 0;
	carPriceArray[subscriptFromMain] = 0.0;

	for(int i = 0; i < carArraySize - 1; i++)
	{
		if(carMakeArray[i] != "")
		{
			carMakeArray[i] = carMakeArray[i + 1];
			carModelArray[i] = carModelArray[i + 1];
			carYearArray[i] = carYearArray[i + 1];
			carPriceArray[i] = carPriceArray[i + 1];

			carMakeArray[i + 1] = "";
			carModelArray[i + 1] = "";
			carYearArray[i + 1] = 0;
			carPriceArray[i + 1] = 0.0;
		}
	}
}
not working means its not compiling or not giving the correct output?
which platform you want to debug it on, windows/unix?
My bad... First it won't compile, then once it does compile, it won't give out the correct output =/
Yes the system clear screen I believe was one of the errors.

Thanks for the care guys!
Topic archived. No new replies allowed.