Program runs with infinite loop?

I have the whole thing coded, I don't see any errors and program doesn't throw any errors, but it'll run and the only thing that will be displayed is "Master File Updating Starting" nothing else and the program also does not stop, it doesn't ever return 0. I'm not sure what's wrong with it, it looks fine to me! It would be greatly appreciated if someone could point me in the right direction here. Thanks.

EDIT: new code added, now I just get an infinite loop saying ""Error Client ID: 0 not in Master File."

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
#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main() 
{
	ifstream masterFile;
	ifstream transactionFile;
	ofstream newMasterFile;
	
	int mClientNumber, mtotalClientCost, tClientNumber, titemClientCost;
	string mClientfName, mClientlName;
	
	cout << "Master File Updating Starting" << endl;
	
	masterFile.open("Master.rtf");
	transactionFile.open("Transaction.rtf");
	newMasterFile.open("newMaster.rtf");
		
	masterFile >> mClientNumber;
	masterFile >> mClientfName;
	masterFile >> mClientlName;
	masterFile >> mtotalClientCost;
	transactionFile >> tClientNumber;
	transactionFile >> titemClientCost;
	
	while(!(transactionFile.eof()))
	{
		while((!(masterFile.eof())) && (mClientNumber < tClientNumber))
		{
		newMasterFile << mClientNumber;
		newMasterFile << mClientfName;
		newMasterFile << mClientlName; 
		newMasterFile << mtotalClientCost;
		masterFile >> mClientNumber;
		masterFile >> mClientfName;
		masterFile >> mClientlName;
		masterFile >> mtotalClientCost;
	    }	
	if(masterFile.eof())
	{
		cout << "Error Client ID: " << tClientNumber << " not in Master File.";
		cout << endl;
	}
	else if(mClientNumber == tClientNumber)
	{
		mtotalClientCost = mtotalClientCost + titemClientCost;
		newMasterFile << mClientNumber;
		newMasterFile << mClientfName;
		newMasterFile << mClientlName;
		newMasterFile << mtotalClientCost;
		masterFile >> mClientNumber;
		masterFile >> mClientfName;
		masterFile >> mClientlName;
		masterFile >> mtotalClientCost;
	}
//This is where the error is occuring at this else if.
	else if(mClientNumber > tClientNumber)
	{
		cout << "Error Client ID: " << tClientNumber << " not in Master File.";
		cout << endl;
	}
	transactionFile >> tClientNumber;
	transactionFile >> titemClientCost;
}

    while(!(masterFile.eof()))
    {
    	newMasterFile << mClientNumber;
    	newMasterFile << mClientfName;
    	newMasterFile << mClientlName;
    	newMasterFile << mtotalClientCost;
    	masterFile >> mClientNumber;
    	masterFile >> mClientfName;
    	masterFile >> mClientlName;
    	masterFile >> mtotalClientCost;   	
	}
	cout << "Master File Updating Complete" << endl;
	masterFile.close();
	transactionFile.close();
	newMasterFile.close();
	return 0;
}


For context this is the masterFile
5 Mike Smith 2098.72
6 Sue Nathan 1234.32
100 Bobby Jones 519.69
125 Sally Mayer 345.74
200 Danny Glover 5623.18


and this is the transactionFile
1 568.34
5 345.10
6 1012.43
17 2045.12
100 1231.00
101 167.39
125 5239.67
Last edited on
closed account (ybf3AqkS)
You might need to read and write to .txt files.
I'll try that real quick, thanks.
Unfortunately it still loops infinitely.
I got it, thanks everyone for all the help, solid advice.
Topic archived. No new replies allowed.