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;
}
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;
}
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