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
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.
#include <iostream>
usingnamespace std;
int main ()
{
int numberofemployees;
float hoursworked,stax;
float grosspay;
float hourlyrate, taxamount, netpay,staxamount;
constint 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.
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.