I am trying to get the program to display the contents of employee.in. I have 10 lines in employee in. When I run the program, only lines 2-10 are displayed. What am I missing?
Thanks! That did the trick. I'm still learning what everything means and when to use it. Taking an online course is more difficult than being in a classroom setting.
So I am making progress with my payroll program. However, I am running into two issues. I am calculating additional taxes for married, single, and head of household. The first problem is that when an employee earns less than $500, there is no tax. If HoH gets a 5% tax reduction. This creates a negative tax deduction which actually adds a positive amount to the gross pay.
The second problem is that I have an employee which grossed $280 (no regular tax) but is single and thus is supposed to have a 5% tax added. This works for the other employees, except for employee 9875.
#include <iostream>
#include <fstream>
usingnamespace std;
int main(){
int hw, id; //hours worked and employee id
float hr, gp, ta, np, TR; //hourly rate, gross pay, tax amount, net pay, tax rate
char msh;
string str;
ifstream fin("employee.in"); //input file
cout << "________________________" << endl; //Program title
cout << " SomeBusiness, Inc" << endl;
cout << "Employee Payroll Program" << endl;
cout << "________________________" << endl;
cout <<endl;
while(fin>>id>>hw>>hr>>msh){
gp = hw * hr;
if( gp > 1000 ) TR = 0.30;
elseif( gp > 800) TR = 0.20;
elseif( gp > 500) TR = 0.10;
else TR = 0.0;
switch(msh)
{
case'S': TR+=0.05;
break;
case'M': TR+=0.10;
break;
case'H': TR-=0.05;
break;
}
np = gp * (1.0-TR);
ta = gp * TR;
cout << "Employee ID Number Is: " << id << endl;
cout << "Total Clocked Hours: " << hw << endl;
cout << "Hourly Pay Rate: $ " << hr << endl;
cout << "Employee Gross Pay This Week: $" << gp << endl;
cout << "Current Tax Rate: " << TR << "%" << endl;
cout << "Tax Deduction Amount: $" << ta << endl;
cout << "Employee Net Pay: $" << np << endl<<endl;
}//while
cout << "Press the enter key to close the program.";
cin.get();
return(0);
}//MAIN
And my employee.in file contents:
1234 40 10.50 M
3214 35 9.00 S
9632 39 10.00 H
9875 26 8.00 S
7454 45 12.00 M
5552 20 11.75 H
1312 50 15.60 M
6713 40 13.56 S
8452 42 20.25 H
9111 60 20.00 M
So your first problem is in the switch statement, you need to check if TR(tax rate) is not 0
1 2 3 4 5 6 7 8 9 10 11 12
switch(msh)
{
case'S': TR+=0.05;
break;
case'M': TR+=0.10;
break;
case'H':
if (TR != 0.0) // if there is tax pay
TR-=0.05; // then decrement tax pay by 0.05
break;
}
#2
No look at employee 9875, he makes 208, not 280. Everything is okay there. 5% of 208 is 10.4 and that is what's taken away.
Another problem you have there is your output, if you look at the first one for example,
Employee ID Number Is: 1234
Total Clocked Hours: 40
Hourly Pay Rate: $ 10.5
Employee Gross Pay This Week: $420
Current Tax Rate: 0.1%
Tax Deduction Amount: $42
Employee Net Pay: $378
The tax pay is not 0.1%, its 0.1 or 10%. So you will have to convert that 0.1, 0.05 etc into a %.
Thanks for your insight! Sorry for the late reply; early the following morning I left for a 6 day road-trip vacation. I turned in the assignment as is and got 100, so I was looking to add things that my professor wasn't looking for. I tend to do that because apart from school assignments, I am really trying to learn which is difficult in this class the way the books and online course is set up.
My professor kept things on schedule regardless of the holiday, so I am scrambling to complete the next assignment, which involves arrays and will probably post a question about that since I am unsure I am doing exactly what he wants and I am running into an error.