Apr 24, 2013 at 1:06am UTC
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
#include <iostream>
#include <iomanip>
using namespace std;
void get_emp_rec(int &id, double &prate, double &hours)
{
cout << "Employee ID is:\t" ;
cin >> id;
cout << "Payrate is:\t" ;
cin >> prate;
cout << "Hours worked are:\t" ;
cin >> hours;
}
double compute_gpay(double hours, double prate)
{
double gpay; // to hold the gross pay
gpay= hours * prate;
return (gpay);
}
double compute_taxes(double gpay)
{
double td; // to hold the tax deduction
if (gpay <= 1000)
td = gpay * 0.05;
else if (gpay < 1500)
td= gpay * 0.06;
else
td= gpay * 0.07;
return (td);
}
double compute_npay(double gpay)
{
double npay, td;
td=compute_taxes(gpay);
npay = gpay - td;
return (npay);
}
void printtables(int ids[], double gpays[], double npays[], int size)
{
for (int j=0; j< size;j++)
{
cout << setw( 7 )<< j << setw( 10 ) << ids[ j ] << endl;
}
cout << "Employee ID" << setw(10)<< "Gross Pay" setw(13) << "Net Pay" << endl;
}
int main()
{
int id=0; // to hold the employee ID number
double gross; // to hold the gross pay
double payr; // to hold the payrate
double hoursW; // to hold the number of hours
double tax; // to hold the tax deduction
double netp=0; // to hold the net pay
double tgross=0; // to hold the total gross pay
double tnet; // to hold the total net pay
int size; // to show how many employees
int empid[10];
double empgrosspay[10];
double empnetpay[10];
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout << setprecision(2); // 2 digits after the decimal point
for (int j=0; j< size; j++)
{
get_emp_rec(id, payr, hoursW);
empid [j] = id;
/**********************Compute the gross pay*******************************/
gross= compute_gpay(hoursW, payr);
empgrosspay[j]= gross;
/*********************Compute net pay**************************************/
netp= compute_npay (gross);
empnetpay[j]= netp;
/********************Compute the total gross and net pay*******************/
tgross = tgross + gross;
tnet = tnet + netp;
cout << endl;
cout << endl;
}
/************************Print the total gross and net pay*********************/
cout << endl << "\nTotal Gross Pay:\t" << tgross;
cout << endl << "\n Total Net Pay:\t" << tnet;
cout << endl;
system ("PAUSE" );
return 0;
}
it wont execute as:
(example)
employee id Gross Pay Net Pay
101 456.23 859.63
102 589.63 785.25
and etc
Last edited on Apr 24, 2013 at 1:07am UTC
Apr 24, 2013 at 1:13am UTC
1. It doesn't even compile as is. Please fix your compiler errors
2. line 68 you're using size without initialising it causing undefined behaviour.
Apr 24, 2013 at 1:16am UTC
but when i compile i dont have an error there
Apr 24, 2013 at 1:17am UTC
it says like 48 is a problem and i tried to fix it but nothing works
Apr 24, 2013 at 1:21am UTC
your missing a << on line 48 between "gross pay" and setw(13). You also need to set size to something like zaita said, and tnet should be initialized to zero or you will have problems on line 80.
Last edited on Apr 24, 2013 at 1:41am UTC
Apr 24, 2013 at 1:24am UTC
so like set size to 10 because there are ten employees in the company? and my professor told me to keep it at size...
Apr 24, 2013 at 5:09pm UTC
Well, presumably you know what size
is supposed to represent, because you wrote the code. So, using that knowledge, you can initialise it to the appropriate value to do what you want it to do.