Need Help with Final step in Payroll program

Ok so i am almost done with the program except now i only need to add the sum of the gross pay for all the employees how would i be able to do that ? thanks
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
#include <iostream>
using namespace std;
 int main ()
{
int numberofemployees;
float hoursworked,stax;
float grosspay;
float hourlyrate, taxamount, netpay,staxamount;
const int SIZE = 80;
char employeeid[SIZE];
float TAXRATE;
numberofemployees = 0;
while( numberofemployees < 4 ){

cout << "ENTER THE EMPLOYEE NAME: ";
cin.getline(employeeid, SIZE);
cout << "ENTER THE HOURS WORKED: ";
cin>>hoursworked;
cout << "ENTER THE HOURLY RATE: ";
cin>>hourlyrate;
cout << "ENTER FEDERAL TAX RATE: ";
cin>>TAXRATE;
cout << "ENTER STATE TAX RATE: ";
cin>>stax;
cin.ignore(SIZE,'\n');
grosspay = hoursworked * hourlyrate;
taxamount = grosspay * TAXRATE/100;
staxamount=grosspay*stax/100;
netpay = grosspay - taxamount;
cout << "EMPLOYEE NAME IS: "<<employeeid << endl;
cout << "YOUR GROSSPAY IS: "<<grosspay << endl;
cout << "YOUR FEDERAL TAX AMOUNT IS: "<<taxamount<<endl;
cout << "YOUR STATE TAX AMOUNT IS: "<<	staxamount<<endl;
cout << "YOUR NETPAY IS: "<<netpay<<endl<<endl;
numberofemployees = numberofemployees + 1;


}//WHILE

  

system("PAUSE");
return 0;
Last edited on
hi

all you need to do is to add another float at the beginning in which you will be adding all those gross payes. and you add a new line after line 36 and write
x += grosspay
x in here is that new float i was talking about and than all you need to do is add new cout after a while loop where you will print x

and you can change line 35 to numberofemployees += 1 it will do the same thing and its better looking.

I hope it make sense to you. because my english is not the best. but if you don t understand something just ask.. i try again.
no actually your English is pretty good , thanks for replying. The only thing i did not really get is am i adding another while loop ? and if so , what is it going to be?
lets call x sum ( the new float you were talking about )
Just a word of advice - your code will be easier to read and understand if you adopt consistent indentation. This will make it easier to see how the control of it flows, and what code will be executed in which scope and under what circumstances. E.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;
int main ()
{
  int numberofemployees;
  float hoursworked,stax;
  float grosspay;
  float hourlyrate, taxamount, netpay,staxamount;
  const int SIZE = 80;
  char employeeid[SIZE];
  float TAXRATE;
  numberofemployees = 0;
  while( numberofemployees < 4 ){

    cout << "ENTER THE EMPLOYEE NAME: ";
    cin.getline(employeeid, SIZE);
    cout << "ENTER THE HOURS WORKED: ";
    cin>>hoursworked;

    // ... the rest of the code within the loop
  }//WHILE

  system("PAUSE");
  return 0;


You can see at a glance which code is inside your main function and which is outside it. You can also see at a glance which code is inside the while loop.
Last edited on
ok let s call it sum. and no you don t add another while loop inside of your while loop you put sum += grosspay;
and after your while loop before system ("pause") you print out sum..
cout << sum<<endl;
and that s it.

and yeah,, you should set your sum to 0 at the beginnig when you are making your new float... float sum = 0; but I am not sure if it is necessary.
please show me of c language, I'm just a beginner
Forgot to thank you for the help, so thank you the program works just as i want :)
any time.. you r welcome.. :)
Topic archived. No new replies allowed.