So I have an assignment where I have to use arrays and output data from an input file.
It use to run, but I made changes and now it will run, but it won't read from the data file. I'm not sure what changes I made, so I am lost as to fix it. Someone told me to rearrange the calculations and taxes and grosspays, which is the change I made. But now, even if I go back to what I had before, it will not run properly.
I am using visual studio 2015
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main() {
ifstream fin("employee.txt");
char SMH; string firstname[10], lastname[15];
int employeeid[100], i = 0;
int hoursworked[100], overtimehours[100];
double hourlyrate[100], regularpay[100];
double overtimepay[100], grosspay[100], taxrate, taxamount, netpay;
int counter = 0;
cout << " EBRAHIMI PAYROLL INSTITUTE" << endl;
cout << " 106 Easy Ways" << endl;
cout << " PLEASENTVILLE, N.Y. 11068" << endl;
while (fin >> employeeid[i] >> firstname[10] >> lastname[15] >> hoursworked[i] >> hourlyrate[i] >> SMH) {
counter = counter + 1;
for (i = 0; i < counter; i++) {
if (hoursworked[i] > 40) {
overtimehours[i] = hoursworked[i] - 40;
overtimepay[i] = overtimehours[i] * hourlyrate[i] * 1.5;
regularpay[i] = 40 * hourlyrate[i];
} else {
overtimehours[i] = 0;
overtimepay[i] = 0;
regularpay[i] = hoursworked[i] * hourlyrate[i];
} } for (i = 0, i < counter; i++;) {
grosspay[i] = hourlyrate[i] + overtimepay[i];
}
for (i = 0; i < counter; i++) {
if (grosspay[i] > 1000) taxrate = 0.30;
else if (grosspay[i] > 800) taxrate = 0.20;
else if (grosspay[i] > 500) taxrate = 0.10;
else taxrate = 0.0;
}
switch (SMH) {
case'S': taxrate += 0.05;
break;
case'M': taxrate += 0.10;
break;
case'H': taxrate -= 0.05;
break;
}
for (i = 0; i < counter; i++) {
taxamount = grosspay[i] * taxrate;
} for (i = 0; i < counter; i++) {
netpay = taxamount - grosspay[i];
}
cout << setw(14) << "Employee Id" << setw(16) << "First Name" << setw(15)
<< "Last Name" << setw(6) << "Stat" << setw(6) << "HW" << setw(6) << "HR" << setw(8) << "Gross" << setw(6)
<< "Tax" << setw(9) << "RegP" << setw(6) << "OTP" << setw(9) << "Netpay" << endl << endl;
for (i = 0; i < counter; i++) {
cout << setw(14) << employeeid[i] << setw(16) << firstname[10] << setw(15) << lastname[15] << setw(6) << SMH
<< setw(6) << hoursworked[i] << setw(6) << hourlyrate[i] << setw(8) << grosspay[i] << setw(6)
<< taxrate << setw(9) << regularpay[i] << setw(6) << overtimepay[i] << setw(9) << netpay << endl;
i = i + 1;
} } fin.close();
system("pause");
return 0;
}
This is the assignment in case my question doesn't deliver the context well:
DR. EBRAHIMI'S PAYROLL INSTITUTE
FIRST NAME LAST NAME STAT SSN HW HR OTH OTP REGP GROSS TAX NET
John Smith M 113 50 20 10 300 800 1100 385 715
Jane Dow M 223 40 15 5 112.5 675 787.5 275 512.5
(The above is supposed to be a table format. It didn't copy well)
B) Take advantage of arrays by breaking programs into separate units. Each unit should have a separate loop. (Do not use functions.)
Read all data into arrays
Compute all the overtimepays
Compute all the grosspays
Compute all the taxrates
Compute all the netpays
Display all the arrays
C) Include separate functions to read in the data, compute the gross pay, tax rate, net pay, and overtime pay for all employees, and display.