Program won't output

We have written a program that should create some .txt files, but it is not working right. The program executes properly otherwise; Visual Studio is not giving us any errors.

We're reading two files (Master and Transactions) into separate arrays, creating two new files as the program runs (Error Log and Master2), then reading Master2 into a third array in order to merge it with the original Master to create NewMaster.txt.

None of these files are being created when the program executes (not even empty text files).

Code follows in the first comment.

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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

struct invRecord
{	string delDate;
	int MID, qtyOnHand, qtyOrdered;
	float price, priceChng;
	bool includeinNewMaster;
};

struct transRecord
{	string actionCode, delDate;
	int TID, qtyOnHand, qtyOrdered;
	float price, priceChng;
};

ostream& operator << (ostream& os, transRecord A)
{os << A.actionCode << "\t" << A.delDate << "\t"<< A.TID << "\t" << A.qtyOnHand << "\t" << A.qtyOrdered << "\t" << A.price << "\t" << A.priceChng; 
return os;}

istream& operator >> (istream& is, transRecord& A)
{is >> A.actionCode >> A.delDate >> A.TID >> A.qtyOnHand >> A.qtyOrdered >> A.price >> A.priceChng; 
return is;}

ostream& operator << (ostream& os, invRecord A)
{os << A.includeinNewMaster << "\t" << A.delDate << "\t"<< A.MID << "\t" << A.qtyOnHand << "\t" << A.qtyOrdered << "\t" << A.price << "\t" << A.priceChng; 
return os;}

istream& operator >> (istream& is, invRecord& A)
{is >> A.delDate >> A.MID >> A.qtyOnHand >> A.qtyOrdered >> A.price >> A.priceChng; 
return is;}

void checktoAdd(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID);
void checktoDelete(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, bool includeinNewMaster);
void checktoEdit1(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, int qtyOnHand);
void checktoEdit2(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, int qtyOrdered, string delDate);
void checktoEdit3(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, string delDate);
void checktoEdit4(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, float priceChng, float price);

int main()
{
	//read in Master.txt to an array of invRecords and set flags to "true"
	invRecord inventory[100];
	ifstream readIn1;
	readIn1.open("Master.txt");
	int count = 0;
	while (!readIn1.eof())
	{
		readIn1 >> inventory[count].MID >> inventory[count].qtyOnHand >> inventory[count].qtyOrdered >> inventory[count].delDate >> inventory[count].price >> inventory[count].priceChng;
		inventory[count].includeinNewMaster = true;
		count = count + 1;
	}
	
	ofstream writeFile;
	ifstream readIn2;
	transRecord transactions[100];
	readIn2.open("Transactions.txt");
	int count2 = 0;
	while (!readIn2.eof())
	{
		readIn2 >> transactions[count2].actionCode >> transactions[count2].TID >> transactions[count2].qtyOnHand >> transactions[count2].qtyOrdered >> transactions[count2].delDate >> transactions[count2].price >> transactions[count2].priceChng;
		count2++;
	}
	
	int index = 0;
	int index2 = 0;
	int MID, TID, qtyOnHand, qtyOrdered;
	bool includeinNewMaster;
	float price, priceChng;
	string actionCode, delDate;
	
	while (index < count && index2 < count2)
	{
		if (inventory[index].MID < transactions[index2].TID)
			{
				index++;
			}
			else
				{
				checktoAdd(inventory, transactions, actionCode, MID, TID);
				checktoDelete(inventory, transactions, actionCode, MID, TID, includeinNewMaster);
				checktoEdit1(inventory, transactions, actionCode, MID, TID, qtyOnHand);
				checktoEdit2(inventory, transactions, actionCode, MID, TID, qtyOrdered, delDate);
				checktoEdit3(inventory, transactions, actionCode, MID, TID, delDate);
				checktoEdit4(inventory, transactions, actionCode, MID, TID, priceChng, price);

				index++, index2++;
				}
	}
	
	invRecord master2[100];
	ifstream readIn;
	readIn.open("Master2.txt");
	int index3 = 0;
	readIn >> master2[index3];
	while (!readIn.eof())
	{
		index3++;
		readIn >> master2[index3];
	}

	int size1 = count;
	int size2 = index3;

	writeFile.open ("NewMaster.txt");
	int i=0, j=0;
	while ((i<count) && (j<index3))
	{
		if ((inventory[i].MID < master2[j].MID) && (inventory[i].includeinNewMaster = true))
		{
			writeFile << inventory[i++];			
		}
		else writeFile << master2[j++];				
		{
			if (i == count)
			{
				while (index3 <= size2)
				writeFile << master2[index3];
			}
			else
			{
				while (count <= size1)
				writeFile << inventory[count];				
			}
		}
	};
	
	readIn.close();	
	readIn1.close();
	readIn2.close();
	writeFile.close();
	return 0;
}

int index=0;
int index2=0;
ofstream writeFile;
transRecord transactions[];
string actionCode, A, D, E1, E2, E3, E4;

void checktoAdd(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID)
{
	if (transactions[index2].actionCode == A)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			writeFile.open ("ErrorLog.txt");
			writeFile << "Record " << inventory[index].MID << " already exists." << endl;
			writeFile.close();
		}
		else
		{
			writeFile.open ("Master2.txt");
			writeFile << transactions[index2].TID  << transactions[index2].qtyOnHand  << transactions[index2].qtyOrdered  << transactions[index2].delDate  << transactions[index2].price  << transactions[index2].priceChng  << endl;
			writeFile.close();
		}
	}
return;
}

void checktoDelete(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, bool includeinNewMaster)
{
	if (transactions[index2].actionCode == D)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			inventory[index].includeinNewMaster = false;
		}
		else
		{
			writeFile.open ("ErrorLog.txt");
			writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
			writeFile.close();
		}
	}
return;
}

void checktoEdit1(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, int qtyOnHand)
{
	if (transactions[index2].actionCode == E1)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			inventory[index].qtyOnHand = (inventory[index].qtyOnHand + transactions[index2].qtyOnHand);
		}
		else
		{
			writeFile.open ("ErrorLog.txt");
			writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
			writeFile.close();
		}
	}
return;
}

void checktoEdit2(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, int qtyOrdered, string delDate)
{
	if (transactions[index2].actionCode == E2)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			(inventory[index].qtyOrdered = transactions[index2].qtyOnHand);
			(inventory[index].delDate = transactions[index2].delDate);
		}
		else
		{
			writeFile.open ("ErrorLog.txt");
			writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
			writeFile.close();
		}
	}
return;
}

void checktoEdit3(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, string delDate)
{
	if (transactions[index2].actionCode == E3)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			(inventory[index].delDate = transactions[index2].delDate);
		}
		else
		{
			writeFile.open ("ErrorLog.txt");
			writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
			writeFile.close();
		}
	}
return;
}

void checktoEdit4(invRecord inventory[], transRecord transactions[], string actionCode, int MID, int TID, float priceChng, float price)
{
	if (transactions[index2].actionCode == E4)
	{
		if (inventory[index].MID == transactions[index2].TID)
		{
			(inventory[index].price = transactions[index2].price);
			(inventory[index].priceChng = (transactions[index2].price - inventory[index].price));
		}
			else 
			{
				writeFile.open ("ErrorLog.txt");
				writeFile << "Record " << inventory[index].MID << " does not exist in Master.txt." << endl;
				writeFile.close();
			}
	}
return;
}

Topic archived. No new replies allowed.