Beginner C++ Employee Payrate Generator

I'm taking an intro to c++ class this semester and I'm a little lost on how to write this program project I have. I was wondering if i could get any help on this from you guys. Here's the requirements off his website
Write a program to process weekly employee time cards and compute pay for all employees of a company. Each employee will have three input data items:

* employee name
* hourly wage rate
* number of hours worked during the week

Employees are to be paid time-and-a-half for all hours over 40 per week. A tax amount of 3.625 percent of gross pay will be deducted. The program output should show each employee's:

* name
* gross pay
* net pay
Try writing a class to hold all the data for the employee, with methods to handle overtime and taxes, adding and subtracting gross and net pay, etc.

This is kind of what Ive started out with. Thanks for the reply
#include <iostream>
using namespace std;

int main()
{
int EmployeeName;
double PayRate, HoursWorked, GrossPay, NetPay;

cout << "Welcome to your employee payslip generator." << endl;
cout << endl;
cout << "Please input your employee's name:";
cin >>EmployeeName;
cout << endl;
cout << "Input hourly wage rate..";
cin >> PayRate;
cout << endl;
cout << "Input hours worked this week..";
cin >> HoursWorked;
cout << endl;




if( HoursWorked > 40);
HoursWorked=HoursWorked*1.5;
GrossPay=HoursWorked*PayRate;
cout <<"Your employees gross pay for this week is" << GrossPay<< endl;
NetPay=GrossPay-(GrossPay* 3.625);
cout <<"And your employees net pay is" << NetPay << endl;

`

else( HoursWorked <=40 , HoursWorked>0);
GrossPay = HoursWorked*PayRate;
cout <<"Your employees gross pay for this week is" << GrossPay <<endl;
NetPay=GrossPay-(GrossPay*3.625);
cout <<"And your employees net pay is" << NetPay << endl;

return 0;
Ok, I would do what QWERTY suggested and make a class to hold your EmployeeName (btw, why is this an int?).

http://www.cplusplus.com/doc/tutorial/classes.html
Yea i messed up on that one. I'm guessing I should have three seperate classes. He explains it on his website
Your program should have four functions namely:

* main()
* inputEmployeeInfo(string &name, float &hours, float & payrate )
* computePay(float &grosspay, float & netpay, float hours, float payrate )
* outputPaySlip(string name, float grosspay, float netpay)
Hmm...I don't know if he wants those as global functions or if methods are ok. Have you gotten to classes, etc in your class yet?
No we havent covered classes yet. Ive fixed a few things since alot of the above was messed up somewhat
Here is a little update on my progress

#include <iostream>
using namespace std;

int main()
{
int EmployeeName;
double PayRate, HoursWorked, GrossPay, NetPay, OTPay;

cout << "Welcome to your employee payslip generator." << endl;
cout << endl;
cout << "Please input your employee's name:";
cin >>EmployeeName;
cout << endl;
cout << "Input hourly wage rate..";
cin >> PayRate;
cout << endl;
cout << "Input hours worked this week..";
cin >> HoursWorked;
cout << endl;




if( HoursWorked > 40)
{

OTPay=HoursWorked*1.5*PayRate;
GrossPay=OTPay-(HoursWorked*PayRate);
cout <<"Your employees gross pay for this week is" << GrossPay<< endl;
NetPay=GrossPay-(3.625/GrossPay*100);
cout <<"And your employees net pay is" << NetPay << endl;
}

`

else if (HoursWorked <=40)
{

GrossPay = HoursWorked*PayRate;
cout <<"Your employees gross pay for this week is" << GrossPay <<endl;
NetPay=GrossPay-(3.625/GrossPay*100);
cout <<"And your employees net pay is" << NetPay << endl;
}


else
cout <<"Sorry your emloyee gets no pay this week..." <<endl;
return 0;

}
Well, you just need to move some of your code into functions like he said. It looks alright (although I haven't actually tested the formulas)
Ok after cleaning things up a bit heres what i have but I'm also getting an error with it to only one. It says "unknown character 0*60" in line 43
#include <iostream>
#include <string>
using namespace std;

int main()
string EmployeeFirstName, EmployeeLastName, EmployeeWholeName;
double HoursWorked, PayRate, OTPay, GrossPay, NetPay;
{
void inputEmployeeInfo()
{

cout << "Welcome to your employee payslip generator." << endl;
cout << endl;
cout << "Please input your employee's first name:";
cin >>EmployeeFirstName;
cout << "Please input your employee's last name:";
cin >>EmployeeLastName;
EmployeeWholeName= EmployeeFirstName + " " + EmployeeLastName;
cout << endl;
cout << "Input hourly wage rate..";
cin >> PayRate;
cout << endl;
cout << "Input hours worked this week..";
cin >> HoursWorked;
cout << endl;
}


int computePay()
{
if(HoursWorked<=40)
GrossPay=HoursWorked*PayRate;
NetPay=GrossPay-(3.625/GrossPay*100);

else if(Hoursworked>40)
OTPay=HoursWorked*1.5*Payrate;
GrossPay=OTPay-(HoursWorked*PayRate);
NetPay=GrossPay-(3.625/GrossPay*100);
}


int outputPay()
{
cout<< EmployeeWholeName <<"'s gross pay is" <<GrossPay<< "and their net pay is" << NetPay;

}

return 0;
}

Put your code in [code][/code] tags next time...Umm, anyway, that's not how you should create functions...look at:

http://www.cplusplus.com/doc/tutorial/functions.html
After working on this for a while longer Ive scratched that whole thing and decided to do it this way. Theirs somethings I need to work out and I'm not sure I did alot of this right due to the huge amount of errors. Here it is

#include<iostream>
#include<string>
using namespace std;

int main()
{

const double RegularHours=40;
int employee_count, another_employee;
double HoursWorked, PayRate, RegularPay, OTPay, GrossPay, NetPay, TotalGrossPay, TotalNetPay, AverageGrossPay,
AverageNetPay;
string EmployeeName;
employee_count=0;

do
{
cout <<"Welcome to you Employee Payslip Generator:" << endl;
cout <<"Please enter your employee's name:"<<endl;
cin >> EmployeeName;
cout <<"Number of hours worked this week? :";
cin>> HoursWorked;
cout<<endl;
cout<<"Employee's Payrate? :";
cin>>PayRate;


if (HoursWorked>RegularHours)
{
OTPay=HoursWorked*1.5*PayRate;
GrossPay=OTPay-(HoursWorked*PayRate);
NetPay=GrossPay-(GrossPay*.03625);
}
else
{
GrossPay=HoursWorked*PayRate;
NetPay=GrossPay-(GrossPay*.03265);
}

TotalGrossPay += GrossPay;
++employee_count;
TotalNetPay += NetPay;
++employee_count;
AverageGrossPay += TotalGrossPay/++employee_count;
AverageNetPay += TotalNetPay/++employee_count;


cout<< EmployeeName <<"'s gross pay is :" << GrossPay <<endl;
cout<< EmployeeName <<"'s net pay is :"<< NetPay <<endl;
cout<< endl;
cout<<"Do you want to process another employee?" <<endl;
cout<<"Enter 1 for yes and 0 for no:"<<endl;
cin<< another_employee;
}

while(another_employee==1)


cout<<"The total gross pay for your employees is:" <<TotalNetPay;
cout<<endl;
cout<<"The total net pay for your employees is:"<<TotalGrossPay;
cout<<endl;
cout<<"The average gross pay for your employees is:"<<AverageGrossPay;
cout<<endl;
cout<<"The average net pay for your employees is:"<<AverageNetPay;
cout<<endl;



return 0;


}

Topic archived. No new replies allowed.