Payroll Program

qstn: Write a program that displays a weekly payroll report. A loop in the program should ask the user for the employee number, gross pay, state tax, federal tax, and FICA withholding. The loop will terminate when 0 is entered for the employee number. After the data is entered, the program should display totals for gross pay,state tax, federal tax, FICA withholdings, and net pay.
Input validation: Do not accept negative numbers for anything. Do not accept values for state, federal or FICA withholdings that are greater than the gross pay. If it happens, show an error message and ask the user to re-enter everything..

*this is how I tried to solve it, but it ain't working. What should I do and what is wrong??:
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
int employeeNum;
double grosspay, state_tax,federal_tax,fica,net_pay;

cout<<"employee nmbr:\n";
cin>>employeeNum;
while (employeeNum!=0)
{
for(int employee=1;employee<=employeeNum;employee++)
{
while(grosspay>0)
{
cout<<"grosspay:\n";
cin>>grosspay;
while(state_tax>0 && state_tax<1)
{
cout<<"state tax:\n";
cin>>state_tax;
state_tax*=grosspay;
while(federal_tax>0 && federal_tax<1)
{
cout<<"federal tax:\n";
cin>>federal_tax;
federal_tax*=grosspay;
while(fica>0 && fica<1)
{
cout<<"FICA:\n";
cin>>fica;
fica*=grosspay;
}
}
}
}
cout<<"Grosspay for employee number"<<employee<<"is $"<<grosspay;
cout<<". His state tax is "<<state_tax<<" federal tax is "<<federal_tax;
cout<<"FICA withholding is "<<fica;
while(net_pay>0)
{
net_pay=grosspay-(state_tax+federal_tax+fica);
}
cout<<"Net pay for Employee"<<employee<<"is =$"<<net_pay;
}
}
return 0;
}
You have several logic issues here are a few:

while(state_tax>0 && state_tax<1)

While state_tax is greater than 0 and less than one.

while(federal_tax>0 && federal_tax<1)

While federal_tax is greater than 0 and less than one.

There are several other issues with your loops, read over http://www.cplusplus.com/doc/tutorial/control/

Here is a while loop:
1
2
3
4
5
//Condition is set
while(SomeCondition){//While our condition is not satisfied
	//We do something else
	//Condition is updated
}


Here is a shell for you:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>

using namespace std;

double SamplePayorTaxFunction();

int main()
{
	int employeeNum;
	double grosspay, state_tax, federal_tax, fica_tax, net_pay;
	//Code Here
	while (employeeNum != 0){
		//Code Here
		while (state_tax + federal_tax + fica_tax > grosspay){
			//Code Here
		}
	}
	//Finish Up
	return 0;
}

double SamplePayorTaxFunction(){

	double num;
	//Code Here
	while (num < 0){
		//Code Here
	}
	return num;
}


Hope this helps.
what is the double SamplePayorTaxFunction() for??
by tawsif95:
Do not accept negative numbers for anything.


Write a function so you don't have to keep rewriting the same code in your main.
Last edited on
Topic archived. No new replies allowed.