PLEASE HELP Program reading from a txt file

I need help. I wrote this code. It takes information from a txt file and calculates pay, tax, and net pay. However, I cant get it to read more than one line. It only reads the first line! Please help!!


// Written By ML 2/20/2015
// This program calculates gross pay for each employee
// It also calculates tax's held and net pay
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
int EmployeeID, Hours;
double Gross, Tax, Pay, Net, Salary;
char Classification;
//Open Folder to get information
//Employee ID, Code for classification, hours, salary
ifstream infile;
infile.open("payData.txt");
cout << "Reading from the file" << endl;
// If it is the incorrect file
if (!infile)
{
cout << "Unable to Open File" << endl;
exit(1); // Stop System
}
while (!infile.eof())
{
{
infile >> EmployeeID >> Classification;
if (Classification == 'H')
{
infile >> Hours >> Pay;
}
else
{
infile >> Salary;
}
}
// Do Calculations Gross
{
if (Classification == 'H')
{
if (Hours > 40)
Gross = (40 * Pay) + ((Hours - 40)* (Pay * 1.5));
else
Gross = Pay * Hours;
}
else
Gross = Salary / 26;
}
// Do Calculations for Tax Withheld
{
if (Gross < 935)
Tax = Gross * .15;
else if (Gross < 2880)
Tax = ((Gross - 935) * .28) + 140.25;
else if (Gross < 4200)
Tax = ((Gross - 2800) * .33) + 680.55;
else if (Gross > 4200)
Tax = Gross * .4;
}
// Do Calculations for Net
{
Net = Gross - Tax;
}

}

// Write Cout statments for user
{
cout << "Employee ID" << " " << "Gross" << " " << "Tax" << " " << "Net" << endl;
cout << EmployeeID << " " << Gross << " " << Tax << " " << Net << endl;
}
//Close the file
infile.close();

system("Pause");
return 0;
}
Please post your code between code tags. They are under "format:"

http://www.cplusplus.com/articles/jEywvCM9/
Code:
// Written By Morgan Cassiday 2/20/2015
// This program calculates gross pay for each employee
// It also calculates tax's held and net pay
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
int EmployeeID, Hours;
double Gross, Tax, Pay, Net, Salary;
char Classification;
//Open Folder to get information
//Employee ID, Code for classification, hours, salary
ifstream infile;
infile.open("payData.txt");
cout << "Reading from the file" << endl;
// If it is the incorrect file
if (!infile)
{
cout << "Unable to Open File" << endl;
exit(1); // Stop System
}
while (!infile.eof())
{
{
infile >> EmployeeID >> Classification;
if (Classification == 'H')
{
infile >> Hours >> Pay;
}
else
{
infile >> Salary;
}
}
// Do Calculations Gross
{
if (Classification == 'H')
{
if (Hours > 40)
Gross = (40 * Pay) + ((Hours - 40)* (Pay * 1.5));
else
Gross = Pay * Hours;
}
else
Gross = Salary / 26;
}
// Do Calculations for Tax Withheld
{
if (Gross < 935)
Tax = Gross * .15;
else if (Gross < 2880)
Tax = ((Gross - 935) * .28) + 140.25;
else if (Gross < 4200)
Tax = ((Gross - 2800) * .33) + 680.55;
else if (Gross > 4200)
Tax = Gross * .4;
}
// Do Calculations for Net
{
Net = Gross - Tax;
}

}

// Write Cout statments for user
{
cout << "Employee ID" << " " << "Gross" << " " << "Tax" << " " << "Net" << endl;
cout << EmployeeID << " " << Gross << " " << Tax << " " << Net << endl;
}
//Close the file
infile.close();

system("Pause");
return 0;
}
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
// Written By Morgan Cassiday 2/20/2015
// This program calculates gross pay for each employee
// It also calculates tax's held and net pay
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main()
{
	int EmployeeID, Hours;
	double  Gross, Tax, Pay, Net, Salary;
	char Classification;
	//Open Folder to get information
	//Employee ID, Code for classification, hours, salary
	ifstream infile;
	infile.open("payData.txt");
	cout << "Reading from the file" << endl;
	// If it is the incorrect file
	if (!infile)
	{
		cout << "Unable to Open File" << endl;
		exit(1); // Stop System
	}
	while (!infile.eof())
	{
		{
			infile >> EmployeeID >> Classification;
			if (Classification == 'H')
			{
				infile >> Hours >> Pay;
			}
			else
			{
				infile >> Salary;
			}
		}
		// Do Calculations Gross
		{
			if (Classification == 'H')
			{
				if (Hours > 40)
					Gross = (40 * Pay) + ((Hours - 40)* (Pay * 1.5));
				else
					Gross = Pay * Hours;
			}
			else
				Gross = Salary / 26;
		}
		// Do Calculations for Tax Withheld
		{
			if (Gross < 935)
				Tax = Gross * .15;
			else if (Gross < 2880)
				Tax = ((Gross - 935) * .28) + 140.25;
			else if (Gross < 4200)
				Tax = ((Gross - 2800) * .33) + 680.55;
			else if (Gross > 4200)
				Tax = Gross * .4;
		}
		// Do Calculations for Net
		{
			Net = Gross - Tax;
		}

	}

	// Write Cout statments for user
	{
		cout << "Employee ID" << "     " << "Gross" << "     " << "Tax" << "          " << "Net" << endl;
		cout << EmployeeID << "         " << Gross << "     " << Tax << "      " << Net << endl;
	}
	//Close the file
	infile.close();

	system("Pause");
	return 0;
}
Could you just edit your first post please. Instead of posting 3 times.
Last edited on
For some reason it wouldn't let me. So I replied and fixed it.
*
Bucky has fantastic tutorials on all kinds of things. If you want to learn about files. Watch video 64-68 - https://www.youtube.com/playlist?list=PLAE85DE8440AA6B83
I didn't see one that refers to this
I still haven't figured this out could someone help please.
this is the txt file
101456 H 20 6.57
100045 S 81994.12
100321 H 45 23.50
101987 H 39 15.76
100486 S 116935.65
100357 H 50 18.19
102003 H 30 12.75
123887 S 226345.43
110441 S 74783.28
101119 H 35 22.22
114532 S 152573.23
100003 H 40 19.00
101285 H 60 29.95
105539 S 130284.54
176531 S 88546.77
101119 H 38 43.15
*
Topic archived. No new replies allowed.