Reading / writing files / eof / setF / setW()

To start, I'm a beginner, so I apologize in advance. I'm trying to write a program that reads 2 sets of number form a file (int id, int calls)and sorts them into eastCalls and westCalls. The file presents the numbers as such

1000 200
1500 300
1600 400
2000 500
2500 600
2600 700

I want my final output to file to look something like this like this.

WEST CALLS: EAST CALLS:
200 500
300 600
400 700
= 900 = 1800

Right now its just reading the last number which is 5000. My screen output is set up how I would want it with the switch statement , but its reading 0 for westCalls, and 5000 for eastCalls. I know that I haven't really started going in the right direction for the output. Any help would be greatly 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
  
#include<iostream>
#include<fstream>
#include<cstdlib>


using namespace::std;

int id = 0;
int calls = 0;
int westCalls = 0;
int eastCalls = 0;


int main()
{

	ifstream inFile;
	ofstream outFile;

	inFile.open("calls.txt");

	if (inFile.fail())
	{
		cout << "Unable to open file" << endl;
		exit(1);
	}

	outFile.open("ProcessedCalls.txt");

	if (outFile.fail())
	{
		cout << "Unable to open file" << endl;
		exit(1);

	}

	inFile >> id >> calls;

	while (!inFile.eof())

		inFile >> id >> calls;
	{
		if (id >= 1000 && id <= 1999)
	{
			westCalls = westCalls + calls;
	}
		if (id >= 2000 && id <= 2999)
	{
			eastCalls = eastCalls + calls;
	}

	int calcTotal = westCalls + eastCalls;
	int menuItem = 5;

	while (menuItem != 0)
	{
		cout << "SELECT FROM MENU: 0 = EXIT, 1 = EAST, 2 = WEST, 3 = ALL " << endl;

		cin >> menuItem;


		switch (menuItem)
		{
		case 0:
			return 0;
			break;

		case 1:
			cout << "Total East Calls " << eastCalls << endl;
			break;

		case 2:
			cout << "Total West Calls " << westCalls << endl;
			break;

		case 3:
			cout << "The total of all call is " << calcTotal << endl;
			break;

		default:
			cout << "Invalid Selection";
			break;
		}

		outFile.setf(ios::right << ios::adjustfield );

		outFile << "WEST CALLS:\n " << westCalls << "\n EAST CALLS: \n" << eastCalls << endl;

	}



	}
	
	inFile.close();
	outFile.close();


}
My output example in my description got squashed when I hit reply.. I'm trying to set the width, setw()?
Topic archived. No new replies allowed.