error ISO C++ forbids...

Greetings,

My professor is allowing an extension for me to work on this and said he will help me so I sent him my code, though I told him that I am going to keep working on it in the meantime.

I was doing "ok" until learning about arrays and trying to modify my previous assignment code to reflect the new material. I have looked at sample code from the text book and other programs but I am unsure how to fit the pieces together.

I have errors starting at line 32. We are supposed to be able to input information and have it come out in tabular format. I may be missing some obvious things because I am exhausted from reading code and posts.

Any help will be greatly appreciated!

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
#include <iostream>
#include <iomanip>

using namespace std;

int main(){

    int hw[100]; //hours worked
    double rp[100], gp[100], otp[100], np[100], TR[100], ta[100]; //regular pay, gross, overtime pay, net, taxes, tax rate,
    double rh[100], oth[100], hr[100], otr[100]; //regular hours, overtime hours, hourly rate, overtime rate
    char id[100], fn[100][14], ln[100][15], st[100]; //first name/last name/status-married, single, head of household
    int counter = 0;
    int i;

	cout<<"Enter Employee First Name, Last Name, Status, SSN, Hours Worked, and Hourly Rate, and then press ctrl z"<<endl;

while(cin>>fn[counter]>>ln[counter]>>st[counter]>>id[counter]>>hw[counter]>>hr[counter])
    counter=counter+1;
    for (i=0; i<counter;i++){
        if(hw[i] > 40){
            oth[i] = hw[i] - 40;
            otr[i] = oth[i] * hr[i] * 1.5;}
            else {oth[i]=0, otr[i]=0;} //loop

    for (i=0; i<counter;i++){
         rp[i]=40 * hr[i];
         if(oth[i] > 0)
         otp[i]=oth[i]*otr[i];
         gp[i]=rp[i]+otp[i];} //loop

    for (i=0; i<counter;i++){
         if( gp > 1000 ) TR = 0.30;
         else if( gp > 800) TR = 0.20;
         else if( gp > 500) TR = 0.10;
         else TR = 0.0;

         if (st[i]=='S') TR[i] = (TR[i] + .05;);
         else if (st[i]=='M') TR[i] = (TR[i] * 1);
         else if (st[i]=='H') TR[i] = (TR[i] - .05);} //loop

     for (i=0; i<counter;i++){
         ta[i] = gp[i] * TR[i];
         np[i] = gp[i] - ta[i];} //loop



      cout<<setw(1)<<"DR. EBRAHIMI'S PAYROLL INSTITUTE"<<
      endl<<endl;

      cout<<setw(8)<<left<<"FIRST NAME"<<setw(9)<<"LAST NAME"<<setw(6)<<"STAT"<<setw(6)<<"SSN"<<setw(4)<<"HW"<<
      setw(5)<<"HR"<<setw(4)<<"OTH"<<setw(6)<<"OTP"<<setw(8)<<"REGP"<<setw(8)<<"GROSS"<<setw(6)<<"TAX"<<
      setw(8)<<"NET"<<endl;
      cout<<setw(8)<<left<<"=========="<<setw(9)<<"========= "<<setw(6)<<"===="<<setw(6)<<"==="<<setw(4)<<"==="<<
      setw(5)<<"==="<<setw(4)<<"==="<<setw(6)<<"==="<<setw(8)<<"====="<<setw(8)<<"====="<<setw(6)<<"===="
      <<setw(3)<<"====="<<endl;

   for (i=0; i<counter;i++){

    cout<<setw(8)<<fn[i]<<setw(9)ln[i]<<setw(6)
    <<st[i]<<setw(6)<<id[i]<<setw(4)<<hw[i]
    <<setw(5)<<hr[i]<<setw(4)<<oth[i]<<setw(6)
    <<otp[i]<<setw(8)<<rp[i]<<setw(8)
    <<gp[i]<<setw(6)<<tr[i]<<setw(1)<<np[i]
    <<endl<<endl;

    cin.get();
    return(0);

}//MAIN
My professor found where I was missing [i] in my tax loop, though now on line 37 I am getting error: expected ')' before ';' token.

Edit: Never mind, I found that problem. I found another error and fixed that, but now I am getting an error on line 69, error: expected '}' at end of input.


Last edited on
line 37 you have an extra ; in the parentheses at the end of the line
(TR[i] + .05;);
Thank you for seeing that. I took care of that and a missing << but am still getting the error on the last line.
You're missing two closing braces for for loops. Also - should all that be in braces for the while loop?

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
    while(cin>>fn[counter]>>ln[counter]>>st[counter]>>id[counter]>>hw[counter]>>hr[counter])
        counter=counter+1;
        for (i=0; i<counter;i++)
        {
            if(hw[i] > 40)
            {
                oth[i] = hw[i] - 40;
                otr[i] = oth[i] * hr[i] * 1.5;
            }
            else 
            {
                oth[i]=0, otr[i]=0;
            } //loop
            
            for (i=0; i<counter;i++)
            {
                 rp[i]=40 * hr[i];
                 if(oth[i] > 0)
                 otp[i]=oth[i]*otr[i];
                 gp[i]=rp[i]+otp[i];
            } //loop

            for (i=0; i<counter;i++)
            {
                 if( gp[i] > 1000 ) TR[i] = 0.30;
                 else if( gp[i] > 800) TR[i] = 0.20;
                 else if( gp[i] > 500) TR[i] = 0.10;
                 else TR[i] = 0.0;
        
                 if (st[i]=='S') TR[i] = (TR[i] + .05);
                 else if (st[i]=='M') TR[i] = (TR[i] * 1);
                 else if (st[i]=='H') TR[i] = (TR[i] - .05);
            } //loop

            for (i=0; i<counter;i++)
            {
                ta[i] = gp[i] * TR[i];
                np[i] = gp[i] - ta[i];
            } //loop

            cout<<setw(1)<<"DR. EBRAHIMI'S PAYROLL INSTITUTE"<<
            endl<<endl;

            cout<<setw(8)<<left<<"FIRST NAME"<<setw(9)<<"LAST NAME"<<setw(6)<<"STAT"<<setw(6)<<"SSN"<<setw(4)<<"HW"<<
            setw(5)<<"HR"<<setw(4)<<"OTH"<<setw(6)<<"OTP"<<setw(8)<<"REGP"<<setw(8)<<"GROSS"<<setw(6)<<"TAX"<<
            setw(8)<<"NET"<<endl;
            cout<<setw(8)<<left<<"=========="<<setw(9)<<"========= "<<setw(6)<<"===="<<setw(6)<<"==="<<setw(4)<<"==="<<
            setw(5)<<"==="<<setw(4)<<"==="<<setw(6)<<"==="<<setw(8)<<"====="<<setw(8)<<"====="<<setw(6)<<"===="
            <<setw(3)<<"====="<<endl;

            for (i=0; i<counter;i++)
            {
                cout<<setw(8)<<fn[i]<<setw(9)<<ln[i]<<setw(6)
                <<st[i]<<setw(6)<<id[i]<<setw(4)<<hw[i]
                <<setw(5)<<hr[i]<<setw(4)<<oth[i]<<setw(6)
                <<otp[i]<<setw(8)<<rp[i]<<setw(8)
                <<gp[i]<<setw(6)<<TR[i]<<setw(1)<<np[i]
                <<endl<<endl;
            }//no closing brace for this for loop
        }//no closing brace for this for outer loop
        cin.get();
        return 0;

}//MAIN 
Thank you again! I found that adding a second closing brace at the end of the first loop compiles without warnings or errors. I tried the code each way and get the same results.

However, the results are not what I expected. The output is all wrong.

EDIT: I know that I have to edit my setw values. However, some of my math prgramming isn't working. I tried to compare with my last program which worked, though the taxes are being added, the overtime hours and pay are being listed as 0, 40hrs * $10 is giving me 440... its all messed up.
Last edited on
I am almost done with this. The only thing left is to show zeroes after decimal points when necessary. I am trying to look this up, though I am trying to get this to my professor asap!

Here is my code:
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
#include <iostream>
#include <iomanip>

using namespace std;

main(){

    int hw[100]; //hours worked
    double rp[100], gp[100], otp[100], np[100], TR[100], ta[100]; //regular pay, gross, overtime pay, net, taxes, tax rate,
    double rh[100], oth[100], hr[100], otr[100]; //regular hours, overtime hours, hourly rate, overtime rate
    char id[100][3], fn[100][14], ln[100][15], st[100]; //first name/last name/status-married, single, head of household
    int counter = 0;
    int i;

	cout<<"Enter Employee First Name, Last Name, Status, SSN, Hours Worked, and Hourly Rate, and then press ctrl z"<<endl;

while(cin>>fn[counter]>>ln[counter]>>st[counter]>>id[counter]>>hw[counter]>>hr[counter])
        counter=counter+1;
        for (i=0; i<counter;i++)// Overtime hours and rate loop
        {
            if(hw[i] > 40)
            {
                oth[i] = hw[i] - 40;
                otr[i] = oth[i] * hr[i] * 1.5;
            }
            else
            {
                oth[i]=0, otr[i]=0;
            } // Overtime hours and rate loop

            for (i=0; i<counter;i++) // Pay loop
            {
                 rp[i] = hw[i] * hr[i];
                 if( oth[i] > 0)
                 otp[i] = (hw[i] - 40) * hr[i] * 1.5;
                 gp[i] = rp[i] + otp[i];
            } // Pay loop

            for (i=0; i<counter;i++) // Tax loop
            {
                 if( gp[i] > 1000 ) TR[i] = 0.30;
                 else if( gp[i] > 800) TR[i] = 0.20;
                 else if( gp[i] > 500) TR[i] = 0.10;
                 else TR[i] = 0.0;

                 if (st[i]=='S') TR[i] = (TR[i] + .05);
                 else if (st[i]=='M') TR[i] = (TR[i] * 1);
                 else if (st[i]=='H') TR[i] = (TR[i] - .05);
            } // Tax loop

            for (i=0; i<counter;i++) //Net pay loop
            {
                ta[i] = gp[i] * TR[i];
                np[i] = gp[i] * (1.0- TR[i]);
            } // Net pay loop

            cout<<endl<<endl<<setw(1)<<"DR. EBRAHIMI'S PAYROLL INSTITUTE"<<
            endl<<endl;

            cout<<setw(12)<<left<<"FIRST NAME"<<setw(10)<<left<<"LAST NAME"<<setw(5)<<"STAT"<<setw(4)<<"SSN"<<setw(4)<<"HW"<<
            setw(6)<<"HR"<<setw(4)<<"OTH"<<setw(7)<<"OTP"<<setw(8)<<"REGP"<<setw(8)<<"GROSS"<<setw(5)<<"TAX"<<
            setw(9)<<"NET"<<endl;

            cout<<setw(12)<<left<<"=========="<<setw(10)<<"========= "<<setw(5)<<"===="<<setw(4)<<"==="<<setw(4)<<"==="<<
            setw(6)<<"====="<<setw(4)<<"==="<<setw(7)<<"======"<<setw(8)<<"======="<<setw(8)<<"======="<<setw(5)<<"===="
            <<setw(9)<<"======="<<endl;

            for (i=0; i<counter;i++)
            {
                cout<<setw(12)<<fn[i]<<setw(10)<<ln[i]<<setw(5)
                <<st[i]<<setw(4)<<id[i]<<setw(4)<<hw[i]
                <<setw(6)<<hr[i]<<setw(4)<<oth[i]<<setw(7)
                <<otp[i]<<setw(8)<<rp[i]<<setw(8)
                <<gp[i]<<setw(5)<<TR[i]<<setw(9)<<np[i]
                <<endl<<endl;
            }
            }
        cin.get();
        return 0;
Last edited on
Do I need to use setprecision anywhere? I am trying to find an example that meets my situation but haven't been able to see a relevant example.
setprecision would let you specify a number of decimal places to print out. If you're calculating dollar and cent amounts, that could be an example of where setprecision would be used. Also possibly hourly rates?
Last edited on
That is what I need it for; both hourly rates and monetary amounts. I have it working for OTP, REGP, GROSS, and NET. When I try to implement it for HR, the OTH gets decimal places as well and I am unsure as to why.

1
2
3
4
5
6
7
8
{
            cout<<setw(12)<<fn[i]<<setw(10)<<ln[i]<<setw(5)
            <<st[i]<<setw(4)<<id[i]<<setw(4)<<hw[i]
            <<setw(6)<<setprecision(2)<<fixed<<hr[i]<<setw(4)<<oth[i]<<setw(7)<<setprecision(2)<<fixed
            <<otp[i]<<setw(8)<<setprecision(2)<<fixed<<rp[i]<<setw(8)
            <<gp[i]<<setw(5)<<TR[i]<<setw(9)<<setprecision(2)<<fixed<<np[i]
            <<endl<<endl;
            }
I may leave it out and toy with it later so that I can turn the program in for grading. I will keep looking into it afterwards. Now I have to alter this program to include functions for the second part of the assignment.
Topic archived. No new replies allowed.