Any ideas with the code:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
int main()
{
int skill, benefitType, skillPay, taxRemainder;
double hours, contPercent, gross, benefitCost, grossDed, contAmount, taxOwed, netSalary, contTotal;
double sumGross = 0, sumBenefit = 0, sumContributions = 0, sumTaxes = 0, sumNet = 0;
string name, taxID, benefitName;
string fileInput1, fileInput2, fileOutput1, fileOutput2;
ifstream fin, fin1;
ofstream fout1, fout2;
// Program title.
cout << " \t Assignment #5: Company Payroll and Employee Reports." << endl;
// Program mission statement.
cout << "This program will prompt user for a data file with a list of a small company's employees, " << endl;
cout << "and will process the data and generate (1) a payroll report and (2) detailed invidiual employee reports." << endl;
cout << "--------------------------------------------------------------" << endl << endl;
cout << "Enter input file name for detailed employee reports in page format: ";
getline(cin, fileInput1);
fin.open(fileInput1.c_str());
if (fin.fail())
cout << "Bad input file." << endl << "Program stopped." << endl;
else
{
cout << "Enter output file name for detailed employee reports in page format: ";
getline(cin, fileOutput1);
fout1.open(fileOutput1.c_str());
fout1 << "Detailed Employee Reports:" << endl;
fin >> skill >> benefitType >> contPercent >> hours;
getline(fin, taxID);
getline(fin, name);
while (!fin.eof())
{
if (skill == 1)
skillPay = 15.00;
else if (skill == 2)
skillPay = 25.00;
else if (skill == 3)
skillPay = 72.00;
else if (skill == 4)
skillPay = 125.00;
if (hours <= 40)
gross = hours * skillPay;
else if (hours <= 50)
gross = (40 * skillPay) + ((hours - 40) * (skillPay * 1.5));
else if (hours <= 60)
gross = (40 * skillPay) + (10 * (skillPay * 1.5)) + ((hours - 50) * (skillPay * 2));
if (skill = 1 || benefitType == 0)
benefitCost = 0;
else if (benefitType == 1)
benefitCost = 32.50;
else if (benefitType == 2)
benefitCost = 52.50;
else if (benefitType == 3)
benefitCost = 62.50;
contAmount = gross * (contPercent / 100);
contTotal = 2 * contAmount;
grossDed = gross - contAmount - benefitCost;
taxRemainder = (grossDed - 5000) / 1000;
if (grossDed <= 2000.00)
taxOwed = 0;
else if (grossDed <= 3000.00)
taxOwed = 0.03 * (grossDed - 2000);
else if (grossDed <= 4000.00)
taxOwed = (0.01 * 3000) + (0.05 * (grossDed - 3000));
else if (grossDed <= 5000.00)
taxOwed = (0.01 * 3000) + (0.05 * 1000) + (0.07 * (grossDed - 4000));
else if (grossDed > 5000.00)
taxOwed = (0.01 * 3000) + (0.05 * 1000) + (0.07 * 1000) + (0.07 + (taxRemainder / 100.0)) * (grossDed - 5000);
netSalary = grossDed - taxOwed;
if (skill < 1 || skill > 4)
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Bad data." << endl << "Invalid skill level." << endl << "Employee data output terminated." << endl << endl;
}
else if (hours < 0 || hours > 60 )
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Bad data." << endl << "Invalid hours." << endl << "Employee data output terminated." << endl << endl;
}
else if (benefitType < 0 || benefitType > 3)
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Gross Salary: $" << gross << endl;
fout1 << "Bad data." << endl <<"Invalid medical benefit code." << endl << "Employee data output terminated." << endl << endl;
}
else if (skill == 4 && contPercent != 0)
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Gross Salary: $" << gross << endl;
fout1 << "Medical Benefits: $" << benefitCost << endl;
fout1 << "Bad data." << endl <<"Invalid retirement contributions for skill level." << endl << "Employee data output terminated." << endl << endl;
}
else if (contPercent < 0 || contPercent > 5)
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Gross Salary: $" << gross << endl;
fout1 << "Medical Benefits: $" << benefitCost << endl;
fout1 << "Bad data." << endl <<"Invalid retirement contributions for skill level." << endl << "Employee data output terminated." << endl << endl;
}
else
{
fout1 << left << fixed << setprecision(2) << setw(6);
fout1 << "------------------------------------------------" << endl;
fout1 << "Name: " << name << endl;
fout1 << "Gross Salary: $" << gross << endl;
fout1 << "Medical Benefits: $" << benefitCost << endl;
fout1 << "Retirement Contribution: " << contPercent << "%" << endl;
fout1 << "\t Company: $" << contAmount << endl;
fout1 << "\t Employee: $" << contAmount << endl;
fout1 << "\t Total: $" << contTotal << endl;
fout1 << "Taxes Owed: $" << taxOwed << endl;
fout1 << "Net Salary: $" << netSalary << endl << endl;
}
fin >> skill >> benefitType >> contPercent >> hours;
getline(fin, taxID);
getline(fin, name);
}
fout1.close();
}
cout << endl;
cout << "Detailed employee reports have been printed in " << fileOutput1 << "." << endl << endl;
cout << "Enter input file name for company payroll report. (Can be same as first input file.): " << endl;
getline(cin, fileInput2);
fin1.open(fileInput2.c_str());
if (fin1.fail())
cout << "Bad input file." << endl << "Program stopped." << endl;
else
{
fin1 >> skill >> benefitType >> contPercent >> hours;
getline(fin1, taxID);
getline(fin1, name);
cout << "Enter output file name for company payroll report: ";
getline(cin, fileOutput2);
fout2.open(fileOutput2.c_str());
cout << "Name \t \t Gross Salary \t Benefits \t Contributions \t Taxes \t Net Salary" << endl;
fout2 << "Name \t \t Gross Salary \t Benefits \t Contributions \t Taxes \t Net Salary" << endl;
while (!fin1.eof())
{
cout << name << " \t \t ";
fout2 << name << " \t \t ";
if (skill < 1 || skill > 4)
{
cout << "Bad data. \t Invalid skill level." << endl;
fout2 << "Bad data. \t Invalid skill level." << endl;
return 0;
}
else if (hours < 0 || hours > 60)
{
cout << "Bad data. \t Invalid hours." << endl;
fout2 << "Bad data. \t Invalid hours." << endl;
return 0;
}
else if (benefitType < 0 || benefitType > 3)
{
cout << "Bad data. \t Invalid benefit code." << endl;
fout2 << "Bad data. \t Invalid benefit code." << endl;
return 0;
}
else if (skill == 1 && benefitType != 0)
{
cout << "Bad data. \t Invalid benefit type for skill level." << endl;
fout2 << "Bad data. \t Invalid benefit type for skill level." << endl;
return 0;
}
else if (skill != 4 && contPercent != 0)
{
cout << "Bad data. \t Invalid contribution percent for skill level." << endl;
fout2 << "Bad data. \t Invalid contribution percent for skill level." << endl;
return 0;
}
else if (contPercent < 0 || contPercent > 5)
{
cout << "Bad data. \t Invalid contribution: " << contPercent << "%" << endl;
fout2 << "Bad data. \t Invalid contribution: " << contPercent << "%" << endl;
return 0;
}
if (skill == 1)
skillPay = 15.00;
else if (skill == 2)
skillPay = 25.00;
else if (skill == 3)
skillPay = 72.00;
else if (skill == 4)
skillPay = 125.00;
if (hours <= 40)
gross = hours * skillPay;
else if (hours <= 50)
gross = (40 * skillPay) + ((hours - 40) * (skillPay * 1.5));
else if (hours <= 60)
gross = (40 * skillPay) + (10 * (skillPay * 1.5)) + ((hours - 50) * (skillPay * 2));
if (skill = 1 || benefitType == 0)
benefitCost = 0;
else if (benefitType == 1)
benefitCost = 32.50;
else if (benefitType == 2)
benefitCost = 52.50;
else if (benefitType == 3)
benefitCost = 62.50;
contAmount = gross * (contPercent / 100);
contTotal = 2 * contAmount;
grossDed = gross - contAmount - benefitCost;
taxRemainder = (grossDed - 5000) / 1000;
if (grossDed <= 2000.00)
taxOwed = 0;
else if (grossDed <= 3000.00)
taxOwed = 0.03 * (grossDed - 2000);
else if (grossDed <= 4000.00)
taxOwed = (0.01 * 3000) + (0.05 * (grossDed - 3000));
else if (grossDed <= 5000.00)
taxOwed = (0.01 * 3000) + (0.05 * 1000) + (0.07 * (grossDed - 4000));
else if (grossDed > 5000.00)
taxOwed = (0.01 * 3000) + (0.05 * 1000) + (0.07 * 1000) + (0.07 + (taxRemainder / 100.0)) * (grossDed - 5000);
netSalary = grossDed - taxOwed;
sumGross += gross;
sumBenefit += benefitCost;
sumContributions += contTotal;
sumTaxes =+ taxOwed;
sumNet += netSalary;
cout << fixed << setprecision(2) << setw(6);
cout << "$" << gross << " \t $" << benefitCost << " \t $" << contAmount << " \t $" << taxOwed << " \t $" << netSalary << endl;
fout2 << fixed << setprecision(2) << setw(6);
fout2 << "$" << gross << " \t $" << benefitCost << " \t $" << contAmount << " \t $" << taxOwed << " \t $" << netSalary << endl;
fin1 >> skill >> benefitType >> contPercent >> hours;
getline(fin1, taxID);
getline(fin1, name);
}
cout << left << fixed << setprecision(2) << setw(6);
cout << "Total Gross Salaries paid: \t \t $" << sumGross << endl;
cout << "Total Benefits collected: \t \t $" << sumBenefit << endl;
cout << "Total Contributions to Retirement Funds: \t \t $" << sumContributions << endl;
cout << "Total Taxes collected: \t \t $" << sumTaxes << endl;
cout << "Total Net Salaries paid: \t \t $" << sumNet << endl;
fout2 << left << fixed << setprecision(2) << setw(6);
fout2 << "Total Gross Salaries paid: \t \t $" << sumGross << endl;
fout2 << "Total Benefits collected: \t \t $" << sumBenefit << endl;
fout2 << "Total Contributions to Retirement Funds: \t \t $" << sumContributions << endl;
fout2 << "Total Taxes collected: \t \t $" << sumTaxes << endl;
fout2 << "Total Net Salaries paid: \t \t $" << sumNet << endl;
fout2.close();
}
return 0;
}
Thanks so much.

New Topic/Question
Reply




MultiQuote






|