Hello guys, fairly new to programming and to this website in general. I need some help with a couple of sample programs, and I'll try to be as explicit as possible. Here is my code:
using namespace std;
int idNumber, unionStatus;
double hours, rate, pay, dues, net, overtime, overtimePay;
outData << fixed << showpoint;
outData << setprecision(2);
outData <<" Weekly Payroll " << endl;
outData << "ID No. Hours Rate Pay Member Dues NetPay " << endl;
outData << endl;
inData >> idNumber>> hours >> rate >> unionStatus >> idNumber>> hours >> rate >> unionStatus;
while (idNumber != -1)
if (hours <= 40)
pay = hours* rate;
else if (hours> 40)
overtime = hours - 40;
overtimePay = overtime * rate * 1.5;
pay = hours* rate + overtimePay;
if (unionStatus == 1)
dues = .10 * pay;
net = pay - dues;
else if (unionStatus == 0)
dues = pay - 5.00;
net = pay - dues;
outData << idNumber << setw(16) << hours << setw(13) << rate
<< setw(13)<< pay << setw(8)<< unionStatus << setw(16)<< dues<< setw(13) << net << endl;
Here is the problem I am trying to solve:
Write a complete program including comments to compute a weekly payroll. The program reads in information for each of the employees of a company and then prints the results. The program does the following for each employee:
a. First, it reads in the data for each employee. Each employee has a three digit identification code (an integer from 100 to 999), hours worked, rate of pay, and union status (1 if the employee is in the union, 0 if not). For example, here are data valued for two typical workers:
123 46 6.50 1
456 32.12 3 0
b. The program computes the weekly pay, which comes from the following formula (this includes an overtime bonus of time and a half for each hour over 40):
if hours are less than or equal to 40, weekly pay is hours times rate
if hours are more than 40 hours, weekly pay is 40 times the rate plus the number of overtime hours times 1.5 times the rate.
Example: ID number 123 would get 40 * 6.50 + 6 * 1.5 * 6.50.
c. The program computes the union dues, which are 10 percent of the weekly pay for union members, and $5 for nonunion members.
d. The program computes net pay, which is weekly pay minus union dues.
e. The program prints all the data values read in and the words "Union" or "Nonunion", plus each item that has been computed. Make sure that all money amounts have exactly two decimal places.
Data: Make sure you handle at least 6 employees. Have at least two employees that are union members and two that are not. Make sure at least 3 employees get overtime.
Output: Create a good looking report. There should be a grand total at the bottom of the report for the total pay, union dues and net pay.
Read the data from an input file - Use the eof function.
Make sure that either a 1 or a 0 is entered for union status. If it is not a valid entry set your dues = 0.
My issue appears to be in my infile variable assignment. I don't know how to use a getline function, so I could use some advice on how to do that. I based this code off of a similar question someone asked here about 4 years ago. It runs, but just prints an infinite loop of data only from the first line of my input file.
If someone could help me to code it so it reads the input data line by line, I'm sure I could figure out how to code it to get the total data.