Payroll Program with Class

Any help with this program would be greatly appreciated. I'm trying to create an employee class for this payroll program to compute the net pay salary for hourly employees. Constant tax rate is supposed to be 30%. My code is below along with the errors I'm receiving.

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
class payroll{
ifstream fin;
char employeeid[12];
char employeename[20];
char maritalstatus;
int hoursworked, overtime;
const float TAXRATE = 0.30;
double hourlyrate, overtimepay, regularpay, grosspay, taxrate, taxamount, netpay;
void calculategrosspay();
void calculatetax();
void calculatenetpay();
void printheadings();
void printdata();
public: payroll();
~payroll();
void printreport(); };
payroll:: payroll(){
fin.open("payroll.in"); }//constructor
payroll:: ~payroll(){
fin.close(); }//destructor
void payroll:: calculategrosspay(){
if (hoursworked > 40){
overtime = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtime * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay; }//if
else grosspay = hoursworked * hourlyrate; }//calculategrosspay
void payroll:: calculatetax(){
taxamount = grosspay * taxrate; }//calculatetax
void payroll:: calculatenetpay(){
netpay = grosspay - taxamount; }//calculatenetpay
void payroll:: printheadings(){
cout<<setw(45)<<"-Payroll Report-"<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Name ID HW OT RT-Pay OT-Pay Gross"
" Tax Netpay"<<endl;
cout<<"-------------------------------------------"<<endl;
}//printheadings
void payroll:: printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<regularpay<<setw(8)
<<overtimepay<<setw(8)<<grosspay<<setw(8)<<taxamount<<setw(8)
<<netpay<<endl; }//printdata
void payroll:: printreport(){
int i = 0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
i++; }//while
}//printreport;
void main(){
payroll employee;
employee.printreport(); }//main


ERRORS:
11 ISO C++ forbids initialization of member `TAXRATE'
11 making `TAXRATE' static
59 `main' must return `int'
Makefile.win [Build Error] [main.o] Error 1
Either make TAXRATE static as the error says or move it outside the class declaration.
The last error is self-explanatory.
hey thanks for the reply...I moved taxrate out of the class declaration and that cleared up one of the errors but I'm still getting another one

Line 59 `main' must return `int'

Any thoughts?
jsmith wrote:
The last error is self-explanatory.


In other words, the main function must return an integer.

1
2
3
4
5
int main()
{
    //...
    return 0;
}
Last edited on
so at what point in the code do I input?

int main()
{
//...
return 0;
}

1
2
3
4
5
6
void main()
{
  payroll employee;
  employee.printreport(); // looks like this method is getting input
  return 0;
}
Awesome...thanks so much! So my errors are resolved but now I'm not getting the output I need..I'm going crazy over here lol. When I compile and run the program my DOS window flashes really quick and closes...here is what my code looks like now

#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;
const float taxrate = 0.30;
class payroll{
ifstream fin;
char employeeid[12];
char employeename[20];
char maritalstatus;
int hoursworked, overtime;
double hourlyrate, overtimepay, regularpay, grosspay, taxrate, taxamount, netpay;
void calculategrosspay();
void calculatetax();
void calculatenetpay();
void printheadings();
void printdata();
public: payroll();
~payroll();
void printreport(); };
payroll:: payroll(){
fin.open("payroll.in"); }//constructor
payroll:: ~payroll(){
fin.close(); }//destructor
void payroll:: calculategrosspay(){
if (hoursworked > 40){
overtime = hoursworked - 40;
regularpay = hoursworked * hourlyrate;
overtimepay = overtime * (hourlyrate * 1.5);
grosspay = regularpay + overtimepay; }//if
else grosspay = hoursworked * hourlyrate; }//calculategrosspay
void payroll:: calculatetax(){
taxamount = grosspay * taxrate; }//calculatetax
void payroll:: calculatenetpay(){
netpay = grosspay - taxamount; }//calculatenetpay
void payroll:: printheadings(){
cout<<setw(45)<<"-Payroll Report-"<<endl;
cout<<"-------------------------------------------"<<endl;
cout<<"Name ID HW OT RT-Pay OT-Pay Gross"
" Tax Netpay"<<endl;
cout<<"-------------------------------------------"<<endl;
}//printheadings
void payroll:: printdata(){
cout<<setprecision(2)<<setiosflags(ios::fixed | ios::showpoint);
cout<<setw(6)<<employeename<<setw(12)<<employeeid<<setw(4)
<<hoursworked<<setw(3)<<overtime<<setw(8)<<regularpay<<setw(8)
<<overtimepay<<setw(8)<<grosspay<<setw(8)<<taxamount<<setw(8)
<<netpay<<endl; }//printdata
void payroll:: printreport(){
int i = 0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>hourlyrate){
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
i++; }//while
}//printreport;
int main()
{
payroll employee;
employee.printreport();
return 0;
}
Topic archived. No new replies allowed.