Error With Payroll Program Using Arrays

I've done this program over and over and can't seem to get it to execute..... Can anybody find my error/errors:

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
#include<iostream.h>
#include<iomanip.h>
main(){
       char empid[100][12];
       char fname[100][14], lastname[100][15];
       int hw[100];
       double gp[100], np[100], hr[100], taxrate[100], taxamt[100];
       int counter=0;
       int i;
       cout<<"ENTER EMP ID, FNAME, LNAME, HRS WORKED, HRLY RATE ctrl z to end"<<endl;
while( cin>>empid[counter]>>fname[counter]>>lastname[counter]>>hw[counter]>>hr[counter])
       counter=counter+1;
       for( i=0;i<counter;i++){
           gp[i]=hw[i]*hr[i];}//end grosspay for loop
       for( i=0;i<counter;i++){
            if(gp[i]>500)taxrate[i]=.30;
            else if(gp[i]>200)taxrate[i]=.20;
       else taxrate[i]=.10;
       }//FOR
       for(i=0;i<counter;i++){
       taxamt[i]=gp[i]*taxrate[i];}//end taxamount for loop
                 for(i=0;i<counter;i++){
                     np[i]=gp[i]-taxamt[i];}//end netpay for loop
                     cout<<endl;
                     cout<<setw(14)<<"EMPLOYEE ID"<<setw(16)<<"FIRST NAME"<<setw(17)
                     <<"LAST NAME"<<setw(4)<<"HW"<<setw(5)<<"HR"<<setw(6)
                     <<"GROSS"<<setw(6)<<"TAX"<<setw(9)<<"NET PAY"<<endl<<endl;
       for(i=0;i<counter;i++){
cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]>>setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;
}//FOR
return 0;
}//MAIN 


I'll take any feedback, thank you
Last edited on
Hi, I am looking at your code and have not got a chance to review it in depth yet. I just wanted to clarify that your trying to make a payroll program to compute employee pay information like for a company right?

Check out http://www.simplecomputerapps.webs.com and try out their payroll app. If this is what you want yours to do, then I can better assist you. That site is mine and that application is mine but I made mine in a completely different way. Your code seems to be much more efficient than the code with which I used to program mine but at the same time, that can cause issues with errors that are harder to find. My program uses a couple hundred lines of code and uses structures as well as arrays but it is easier to spot issues when they occur.

If you have time, check it out and let me know how I can assist you further.
Syntax problems on lines 3 and 30
Hey you did just small mistake your code is working at all..

your code at line 29-30
cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]">>"setw(6)<<taxamt[i]<<setw(9)<<np[i]<<endl;

correct one is
cout<<setw(14)<<empid[i]<<setw(16)<<fname[i]<<setw(17)<<lastname[i]<<setw(4)
<<hw[i]<<setw(5)<<hr[i]<<setw(6)<<gp[i]"<<"setw(6[/quote])<<taxamt[i]<<setw(9)<<np[i]<<endl;

you did >> in place of <<
gud luck..
Oh, and another thing i just noticed is your main function is not set up to run as a function. You need to declare it as an "int" type in front of the word main().
I figured out my small errors and it finally executed but thanks for all of the help.
Topic archived. No new replies allowed.