Unknown error during compiling

I am trying to code a basic program that computes the netpay for an employee and displays a report on the screen. Please see the purpose for full details. The compiler reports the following error for the same line.

"expected `while' before "withHolding""
"expected `(' before "withHolding""
"expected `)' before ';' token"

I have placed a comment line where the error reports. I am not sure what is causing the problem. Can anyone explain what error i done, how to fix it and a better way to tackle the program's objective? Thank you in advance for any help.

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
91
92
93
94
// Purpose: The program will be designed to display a weekly payroll report.The 
//          user will be asked to enter the employee number, gross pay, state
//          tax, federal tax and FICA withholdings. The value of 0 for the
//          employee will terminate the loop. INPUT VALIDATION: the program will
//          not accept negative numbers for any items. The program will reject
//          values that exceed the goss pay. If the total withholding exceed
//          goss pay, the program will prompt the user the reenter the data for
//          that employee.
// *****************************************************************************

#include <iostream>

using namespace std;

int main ()
{
    
    // declare Constants
    
    
    // declare Variables
    int employeeNumber = 0,
        gossPay = 0,
        stateTax = 0,
        federalTax = 0,
        fica = 0,
        withHolding = 0,
        netPay = 0;
 
    do while (employeeNumber !=0)
    {
        cout << "Please enter the employee number: ";
        cin >> employeeNumber;
        
        if (employeeNumber < 0)
        {
            cout << "\nERROR! employee number can not be a negative value.";
            cout << " Try again: ";
            cin >> employeeNumber;
        }
        
        cout << "\nPlease enter the employee's goss pay: ";        
        cin >> gossPay;
        
        if (gossPay < 0)
        {
            cout << "\nERROR! employee can not earn a negative value.";
            cout << " Try again: ";
            cin >> gossPay;
        }    
            
          cout << "Please enter the employee's STATE TAX: ";
        cin >> stateTax;
        
        if (stateTax < 0 || stateTax > gossPay)
        {
            cout << "\nERROR! STATE TAX can not be a negative value or exceed"<<
            cout << " the goss pay. Try again: ";
            cin >> stateTax;
        }
        
        cout << "\nPlease enter the employee's FEDERAL TAX: ";        
        cin >> federalTax;
        
        if (federalTax < 0 || federalTax > gossPay)
        {
            cout << "\nERROR! FEDERAL TAX can not earn a negative value or";
            cout << " exceed the gross pay. Try again: ";
            cin >> federalTax;
        }   
            
        cout << "\nPlease enter the employee's FICA: ";        
        cin >> fica;
        
        if (fica < 0 || fica > gossPay)
        {
            cout << "\nERROR! FICA can not earn a negative value.";
            cout << " Try again: ";
            cin >> fica;
        }   
    }
    
    // compute the withholding and net pay 
        withHolding = fica+federalTax+stateTax; //Error flagged on this line.
        netPay = gossPay - withHolding;
            
        cout << "with Holding " << withHolding;
        cout << "net pay " << netPay;   
            
    system("pause");
    return 0;
    
}
    
1
2
3
4
5
6
7
8
9
10
11
12
// ...

// ...

do /*while (employeeNumber !=0) */ // ****
{
    cout << "Please enter the employee number: ";
    // ...
    
    // ...
    
} while (employeeNumber !=0) ; // **** 


See: http://msdn.microsoft.com/en-us/library/b0kk5few(v=vs.100).aspx
Last edited on
Possible to go into a bit more detail on how it should be done?
I attempted to make the change as shown by JLBorges and the link was helpful. I am not exactly sure how to get it to move forward and the complier reports errors on line 38, 88, 89, 91, 94, 95, and 97. I believe it is only one error creating problems along the lines. most of the errors relate to the ; out of place. I don't see where it is missing. here is the modified 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// *****************************************************************************
// Program:
// Author:
// Date:
// Purpose: The program will be designed to display a weekly payroll report.The 
//          user will be asked to enter the employee number, gross pay, state
//          tax, federal tax and FICA withholdings. The value of 0 for the
//          employee will terminate the loop. INPUT VALIDATION: the program will
//          not accept negative numbers for any items. The program will reject
//          values that exceed the goss pay. If the total withholding exceed
//          goss pay, the program will prompt the user the reenter the data for
//          that employee.
// *****************************************************************************

#include <iostream>

using namespace std;

int main ()
{
    
    // declare Variables
    int employeeNumber = 0,
        gossPay = 0,
        stateTax = 0,
        federalTax = 0,
        fica = 0,
        withHolding = 0,
        netPay = 0;
 
    do 
    {
        cout << "Please enter the employee number: ";
        cin >> employeeNumber;
    }
    
        while (employeeNumber !=0)   
    {
            if (employeeNumber < 0)
        {
            cout << "\nERROR! employee number can not be a negative value.";
            cout << " Try again: ";
            cin >> employeeNumber;
        }
        
        cout << "\nPlease enter the employee's goss pay: ";        
        cin >> gossPay;
        
        if (gossPay < 0)
        {
            cout << "\nERROR! employee can not earn a negative value.";
            cout << " Try again: ";
            cin >> gossPay;
        }    
            
          cout << "Please enter the employee's STATE TAX: ";
        cin >> stateTax;
        
        if (stateTax < 0 || stateTax > gossPay)
        {
            cout << "\nERROR! STATE TAX can not be a negative value or exceed"<<
            cout << " the goss pay. Try again: ";
            cin >> stateTax;
        }
        
        cout << "\nPlease enter the employee's FEDERAL TAX: ";        
        cin >> federalTax;
        
        if (federalTax < 0 || federalTax > gossPay)
        {
            cout << "\nERROR! FEDERAL TAX can not earn a negative value or";
            cout << " exceed the gross pay. Try again: ";
            cin >> federalTax;
        }   
            
        cout << "\nPlease enter the employee's FICA: ";        
        cin >> fica;
        
        if (fica < 0 || fica > gossPay)
        {
            cout << "\nERROR! FICA can not earn a negative value.";
            cout << " Try again: ";
            cin >> fica;
        }   
    }    }
    
    // compute the withholding and net pay 
        withHolding = fica+federalTax+stateTax; //Error flagged on this line.
        netPay = gossPay - withHolding;
            
        cout << "with Holding " << withHolding;
        cout << "net pay " << netPay;   
            
    system("pause");
    return 0;
    
}
I think you are getting thoroughly mixed up between a while-loop and a do-while-loop.

Perhaps, re-reading about these looping constructs in your text book is what is required first.
Or peruse on-line tutorials like this: http://www.cprogramming.com/tutorial/lesson3.html

I went back and reviewed both links and the textbook. I was able to get it to compile successfully. I seem to have two logical problems to deal with. The biggest one, the program will not advance unless you enter 0 for the employee. this value is suppose to terminate the program. The second issue is the program do-while is not repeating after each run. Here is the new 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Purpose: The program will be designed to display a weekly payroll report.The 
//          user will be asked to enter the employee number, gross pay, state
//          tax, federal tax and FICA withholdings. The value of 0 for the
//          employee will terminate the loop. INPUT VALIDATION: the program will
//          not accept negative numbers for any items. The program will reject
//          values that exceed the goss pay. If the total withholding exceed
//          goss pay, the program will prompt the user the reenter the data for
//          that employee.
// *****************************************************************************

#include <iostream>

using namespace std;

int main ()
{
    
    // declare Variables
    int employeeNumber = 0,
        gossPay = 0,
        stateTax = 0,
        federalTax = 0,
        fica = 0,
        withHolding = 0,
        netPay = 0;

    do
    {
      cout << "Please enter the employee number: ";
      cin >> employeeNumber;
      
    }
    while (employeeNumber != 0);
    {
        if (employeeNumber < 0)
        {
            cout << "\nERROR! employee number can not be a negative value.";
            cout << " Try again: ";
            cin >> employeeNumber;
        }
        
        cout << "\nPlease enter the employee's goss pay: ";        
        cin >> gossPay;
        
        if (gossPay < 0)
        {
            cout << "\nERROR! employee can not earn a negative value.";
            cout << " Try again: ";
            cin >> gossPay;
        }    
           
          cout << "Please enter the employee's STATE TAX: ";
        cin >> stateTax;
        
        if (stateTax < 0 || stateTax > gossPay)
        {
            cout << "\nERROR! STATE TAX can not be a negative value or exceed"<<
            cout << " the goss pay. Try again: ";
            cin >> stateTax;
        }
        
        cout << "\nPlease enter the employee's FEDERAL TAX: ";        
        cin >> federalTax;
        
        if (federalTax < 0 || federalTax > gossPay)
        {
            cout << "\nERROR! FEDERAL TAX can not earn a negative value or";
            cout << " exceed the gross pay. Try again: ";
            cin >> federalTax;
        }   
            
        cout << "\nPlease enter the employee's FICA: ";        
        cin >> fica;
        
        if (fica < 0 || fica > gossPay)
        {
            cout << "\nERROR! FICA can not earn a negative value.";
            cout << " Try again: ";
            cin >> fica;
        }   
    
     // compute the withholding and net pay 
        withHolding = fica+federalTax+stateTax;
        netPay = gossPay - withHolding;
     
     // display to screen       
        cout << "\n\nGoss Pay " << gossPay << endl;
        cout << "State Tax " << stateTax << endl;   
        cout << "Federal Tax " << federalTax << endl;
        cout << "FICA withholding " << netPay << endl;   
        cout << "Net Pay: " << netPay << endl << endl;    

    }
    
    system("pause");
    return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// declare Variables
int employeeNumber = 0 ;
// ...

do // START OF DO-WHILE LOOP
{
    // read in a non-negetive employee number
    cin >> employeeNumber ;
    while( employeeNumber < 0 )
    {
        cout << "\nERROR! employee number can not be a negative value.";
        cout << " Try again: ";
    } // end while

    if( employeeNumber == 0 ) break ; // EXIT DO-WHILE LOOP (do on line 5)

    // read in pay, tax etc.

    // compute various stuff

    // display results

} while( employeeNumber != 0 ) ; // END OF DO-WHILE LOOP (do on line 5) 
I deleted what I have done and started from the ground up. I know it is a small problem. The program seems to run correctly unltil the user tries to quit. In order for the program to end is to enter the value of 0 for all prompts. It is suppose to end when the employee number equals to 0 only. Can anyone please show me exactly where I am in error and how to correct it?

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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Purpose: The program will be designed to display a weekly payroll report.The 
//          user will be asked to enter the employee number, gross pay, state
//          tax, federal tax and FICA withholdings. The value of 0 for the
//          employee will terminate the loop. INPUT VALIDATION: the program will
//          not accept negative numbers for any items. The program will reject
//          values that exceed the goss pay. If the total withholding exceed
//          goss pay, the program will prompt the user the reenter the data for
//          that employee.
// *****************************************************************************

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    // Declared Variables

    int ficaWithholding=0,
        employeeNumber=0,
        grossPay=0,
        stateTax=0,
        federalTax=0,
        withHolding=0,
        netPay=0;

    do
    {  
        cout << "Please enter the employee number: ";
        cin >> employeeNumber;
        
        // Employee Number validation
        
        if (employeeNumber < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee number can not be a negative ";
            cout <<"value. Try again:";
            cin >> employeeNumber;
        }
        
        cout << "Please enter the employee Goss Pay: ";
        cin >> grossPay;
        
        // Employee Gross Pay validation
        
        if (grossPay < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee gross pay can not be a negative ";
            cout <<"value. Try again:";
            cin >> grossPay;
        }
        
        cout << "Please enter the employee State Tax: ";
        cin >> stateTax;
        // Employee State Tax validation
        
        if (stateTax < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee state tax can not be a negative ";
            cout <<"value. Try again:";
            cin >> stateTax;
        }
        
        cout << "Please enter the employee Federal Tax: ";
        cin >> federalTax;
        
        // Employee Federal Tax validation
        
        if (federalTax < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee federal tax can not be a negative";
            cout <<" value. Try again:";
            cin >> grossPay;
        }
        
        cout << "Please enter the employee FICA Withholding: ";
        cin >> ficaWithholding;
        
        // Employee Federal Tax validation
        
        if (ficaWithholding < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee FICA Withholding can not be a";
            cout <<" negative value. Try again:";
            cin >> withHolding;
        }
       
          // computes the net pay
    
    netPay = grossPay -(ficaWithholding + federalTax + stateTax);
     
    //output to console screen
    
    cout << fixed << showpoint << setprecision(2);
    cout <<"\n  Gross Pay: $" << grossPay << endl;
    cout <<"  State Tax: $" << stateTax << endl;
    cout <<"Federal Tax: $" << federalTax << endl;
    cout <<"    Net Pay: $" << netPay << endl << endl;
    
    
    } while (employeeNumber !=0);

    system("pause");
    return 0;

}
Last edited on
To exit immediately if the employee number entered is zero,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
    do
    {  
        cout << "Please enter the employee number: ";
        cin >> employeeNumber;
        
        // Employee Number validation
        
        if (employeeNumber < 0)
        {
            cout << "\n";
            cout <<"ERROR DECTECTED! Employee number can not be a negative ";
            cout <<"value. Try again:";
            cin >> employeeNumber;
        }
       if( employeeNumber == 0 ) return 0 ; // **** added **** 
         // quit program immediately by returning from main 

     
       // .... 
Last edited on
Thank you very much for the help.
Topic archived. No new replies allowed.