Jul 26, 2009 at 4:49am UTC
I created a program for payroll calculations using Dev C++4.9.9.2. I compiled the program but get no printout. I inserted a "cout" function but only get "Press any key to continue." I believe my problem is in reading the input file. I've tried several different input code routines but get the same response. Below is my code for this program:
#include<fstream>
#include<iostream>
#include<iomanip>
using namespace std;
class payroll{
ifstream fin;
char employeeid[3];
char employeename[25];
char maritalstatus;
int hoursworked,overtime,counter;
double hourlyrate,overtimepay,regularpay,grosspay,taxrate,taxamount,
netpay,totalnetpay,avgnetpay;
void calculategrosspay();
void calculatetax();
void calculatenetpay();
void calculateavgnetpay();
void printheadings();
void printdata();
public: payroll();
~payroll();
void printreport();};
payroll::payroll(){
fin.open("payrollinfo.txt");
cout<<employeename<<endl;}
payroll::~payroll(){
fin.close();}
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(){
taxrate=.3;
taxamount=grosspay*taxrate;}//CALCULATETAX
void payroll::calculatenetpay(){
int counter=0;
netpay=grosspay-taxamount;
totalnetpay=totalnetpay+netpay;
counter=counter+1;}//CALCULATENETPAY
void payroll::calculateavgnetpay(){
avgnetpay=totalnetpay/counter;}//CALCULATEAVGNETPAY
void payroll::printheadings(){
cout<<setw(50)<<"Payroll Report"<<endl;
cout<<"Name HW HR OT RPay OTPay Tax Net Pay"
<<endl;}//PRINTHEADINGS
void payroll::printdata(){
cout<<setprecision(2);
cout<<setw(12)<<employeename<<setw(4)<<hoursworked<<setw(8)<<hourlyrate
<<setw(3)<<setw(8)<<regularpay<<setw(8)<<overtimepay<<setw(8)
<<taxamount<<setw(9)<<netpay<<endl;}//PRINTDATA
void payroll::printreport(){
int i=0;
printheadings();
while(fin>>employeename>>employeeid>>maritalstatus>>hoursworked>>
hourlyrate){
calculategrosspay();
calculatetax();
calculatenetpay();
printdata();
i=i+1;}//WHILE
cout<<"Average Net Pay is:";
cout<<avgnetpay<<endl;
}//PRINTREPORT
int main(){
payroll employee;
employee.printreport();
system("pause");
}//MAIN
Hopefully, someone can steer me in the right direction.
Jul 26, 2009 at 8:57am UTC
The code hurts my eyes...
Please use appropriate spaces/tabs/blank lines, and code tags [co de][/code].