payroll report

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
// Includes
#include "stdafx.h"
#include <iostream>
#include <conio.h>
using namespace std;

// Main Function
int main()
{
	cout << "This will display a payroll report.\n\n";

	// Loop to do everything
	do
	{
		int employeenum;
		float gross, statetax, federaltax, fica;
		double spay, fpay, ficapay, netpay;
		
		cout.setf(ios_base::fixed, ios_base::floatfield);
		cout.precision(2);

		spay = gross * statetax;
		fpay = gross * federaltax;
		ficapay = gross - fica;
		netpay = spay - fpay - fica;

		cout << "Enter the employee number: ";
		cin >> employeenum;
		cout << "Enter gross pay: $";
		cin >> gross;
		cout << "Enter state tax percent in decimal form (EX. 40% = .40): ";
		cin >> statetax;
		cout << "Enter federal tax percent in decimal form (EX. 40% = .40): ";
		cin >> federaltax;
		cout << "Enter FICA withholdings: $";
		cin >> fica;
			
		cout << "\n\n";

		// What hapens went a negative number is entered
		while (employeenum < 0 || gross < 0 || statetax < 0 || federaltax <  0 || fica < 0)
		{
			// Makes user re-enter data because user entered a number less than 0
			cout << "Re-enter data must be greter than 0: ";
			cin >> employeenum;
			cout << "$ ";
			cin >> gross;
			cin >> statetax;
			cin >> federaltax;
			cout << "$ ";
			cin >> fica;
		}

		cout << "Payroll Report:\n\n";
		cout << "The Employee Number is: " << employeenum << endl;
		cout << "You gross pay is: $" << gross << endl;
		cout << "Your state tax total is: $" << spay << endl;
		cout << "Your federal tax total is: $" << fpay << endl;
		cout << "Your FICA pay is: $" << fica << endl;
		cout << "Your total netpay is: $" << netpay << endl;
	} while (employeenum == 0);
	_getch();

	return 0;
}


Am i missing something or putting something somewhere where it doesnt belong.

This program is suppose to keep running until the user enters 0 as the employeenum, but when i goto compile it it says

payroll report.cpp(61): error C2065: 'employeenum' : undeclared identifier

this part is the error

 
} while (employeenum == 0)


any ideas why or what im doing wrong?
you encapsulated the declaration of employeenum in the scope of the do - while statement, this means that employeenum is not defined outside of the paranthesis { ... }. But while (employeenum == 0) is not within this block of course, so employeenum is unknown.

To solve this problem you just need to move the declaration of employeenum in front of the do-while statement.
Last edited on
ok thank you
Topic archived. No new replies allowed.