Help with C++, please.

I am stuck as to why there are build errors in my code.
For my code, I have to ask the user to input the employee's number, gross pay, state tax, federal tax, and FICA withholdings. It keeps on looping until the user enters 0. And also I need to have a total of the gross pay, federal tax, state tax, and FICA withholdings. Then I find the total net pay.

This is what it says for the Build error output:
"1>------ Build started: Project: IC09_PayrollReport, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(69): error C2143: syntax error : missing ';' before '}'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="

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;

int main() {
	int employeeNum, grossPay, stateTax, federalTax, fICA,
		totalGross, totalState, totalFederal, totalFICA, totalNet;
	do {
		if (employeeNum <= 0 || cin.fail()) {
			cout << "Please enter the employee number (enter 0 to quit): ";
			cin >> employeeNum;
			cout << "Error: employee number must be a number greater than or equal to 0." << endl;
			cin.clear();
			cin.ignore(INT_MAX, '\n');
		}

		else {
			cout << "Please enter the employee number (enter 0 to quit): ";
			cin >> employeeNum;
			if (grossPay < 0 || cin.fail()) {
				cout << "Please enter gross pay: $";
				cin >> grossPay;
				cout << "Error: gross pay must be a number greater than or equal to 0." << endl;
				cin.clear();
				cin.ignore(INT_MAX, '\n');
			}
			else {
				cout << "Please enter gross pay: $";
				cin >> grossPay;
				totalGross = totalGross + grossPay;
				if (stateTax < 0 || cin.fail()) {
					cout << "Please enter state tax: $";
					cin >> stateTax;
					cout << "Error: state tax must be a number greater than or equal to 0." << endl;
					cin.clear();
					cin.ignore(INT_MAX, '\n');
				}
				else {
					cout << "Please enter state tax: $";
					cin >> stateTax;
					totalState = totalState + stateTax;
					if (federalTax < 0 || cin.fail()) {
						cout << "Please enter federal tax: $";
						cin >> federalTax;
						cout << "Error: federal tax must be a number greater than or equal to 0." << endl;
						cin.clear();
						cin.ignore(INT_MAX, '\n');
					}
					else {
						cout << "Please enter federal tax: $";
						cin >> federalTax;
						totalFederal = totalFederal + federalTax;
						if (fICA < 0 || cin.fail()) {
							cout << "Please enter FICA withholdings: $";
							cin >> fICA;
							cin.clear();
							cin.ignore(INT_MAX, '\n');
						}
						else {
							cout << "Please enter FICA withholdings: $";
							cin >> fICA;
							totalFICA = totalFICA + fICA;
							cout << "\n"
						}
					}
				}
			}
		}
	} while (employeeNum != 0);

	totalNet = totalGross - (totalState + totalFederal + totalFICA);
	cout << "Total gross pay: $" << setprecision(2) << fixed << totalGross
		<< "\nTotal state tax: $" << totalState << "\nTotal federal tax: $"
		<< totalFederal << "\nTotal FICA withholdings: $" << totalFICA
		<< "\n\nTotal net pay: $" << totalNet << endl;

	system("pause");
	return 0;
}
Last edited on
Look for missing semicolons at or before the line indicated in your error message. Also where is INT_MAX defined?

Okay, managed to find the missing semicolon. Also was I suppose to define INT_MAX? Usually when I do that, it works.
You either need to define a variable with that name or #include the proper standard header file that defines that value.

Okay, I have a question. How do I have the line numbers printed on the side of my code like the one above in visual studio?
I can't tell which line number I have to fix.
I'm not familiar with Visual Studio but perhaps if you click on the error the editor will go to the correct line number?
How do I have the line numbers printed on the side of my code like the one above in visual studio?

Tools->Options->Text Editor->All Languages->Check the the Line Numbers box.

I prefer not to have the line numbers displayed. If I need to go to a particular line number, CTRL-G will open a GOTO line number dialog. You can also double click on the diagnostic message and VS will take you to the line automatically. The current line number is always displayed on the bottom border of the window.

Managed to find how to have the numbered lines, but I am still confused as to why there are build errors on those lines.

This is the build errors now:
"1>------ Build started: Project: IC09_PayrollReport, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(15): error C4700: uninitialized local variable 'employeeNum' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(26): error C4700: uninitialized local variable 'grossPay' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(36): error C4700: uninitialized local variable 'totalGross' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(37): error C4700: uninitialized local variable 'stateTax' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(47): error C4700: uninitialized local variable 'totalState' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(48): error C4700: uninitialized local variable 'federalTax' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(58): error C4700: uninitialized local variable 'totalFederal' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(59): error C4700: uninitialized local variable 'fICA' used
1>c:\users\randy\desktop\ic09_payrollreport\ic09_payrollreport\source.cpp(68): error C4700: uninitialized local variable 'totalFICA' used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped =========="

And then the 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
/*
Nguyen, Randy
March 7, 2016
IC09_PayrollReport
*/
# include <iostream>
# include <iomanip>
# include <climits>
using namespace std;

int main() {
	int employeeNum, grossPay, stateTax, federalTax, fICA,
		totalGross, totalState, totalFederal, totalFICA, totalNet;
	do {
		if (employeeNum <= 0 || cin.fail()) {
			cout << "Please enter the employee number (enter 0 to quit): ";
			cin >> employeeNum;
			cout << "Error: employee number must be a number greater than or equal to 0." << endl;
			cin.clear();
			cin.ignore(INT_MAX, '\n');
		}

		else {
			cout << "Please enter the employee number (enter 0 to quit): ";
			cin >> employeeNum;
			if (grossPay < 0 || cin.fail()) {
				cout << "Please enter gross pay: $";
				cin >> grossPay;
				cout << "Error: gross pay must be a number greater than or equal to 0." << endl;
				cin.clear();
				cin.ignore(INT_MAX, '\n');
			}
			else {
				cout << "Please enter gross pay: $";
				cin >> grossPay;
				totalGross = totalGross + grossPay;
				if (stateTax < 0 || cin.fail()) {
					cout << "Please enter state tax: $";
					cin >> stateTax;
					cout << "Error: state tax must be a number greater than or equal to 0." << endl;
					cin.clear();
					cin.ignore(INT_MAX, '\n');
				}
				else {
					cout << "Please enter state tax: $";
					cin >> stateTax;
					totalState = totalState + stateTax;
					if (federalTax < 0 || cin.fail()) {
						cout << "Please enter federal tax: $";
						cin >> federalTax;
						cout << "Error: federal tax must be a number greater than or equal to 0." << endl;
						cin.clear();
						cin.ignore(INT_MAX, '\n');
					}
					else {
						cout << "Please enter federal tax: $";
						cin >> federalTax;
						totalFederal = totalFederal + federalTax;
						if (fICA < 0 || cin.fail()) {
							cout << "Please enter FICA withholdings: $";
							cin >> fICA;
							cin.clear();
							cin.ignore(INT_MAX, '\n');
						}
						else {
							cout << "Please enter FICA withholdings: $";
							cin >> fICA;
							totalFICA = totalFICA + fICA;
							cout << "\n";
						}
					}
				}
			}
		}
	} while (employeeNum != 0);

	totalNet = totalGross - (totalState + totalFederal + totalFICA);
	cout << "Total gross pay: $" << setprecision(2) << fixed << totalGross
		<< "\nTotal state tax: $" << totalState << "\nTotal federal tax: $"
		<< totalFederal << "\nTotal FICA withholdings: $" << totalFICA
		<< "\n\nTotal net pay: $" << totalNet << endl;

	system("pause");
	return 0;
}
Line 12; What value do you think employeeNum has? hint: garbage.

Line 15: What value of employeeNum do you think you're testing? See line 12 for hint.

Line 26, 36, etc: ditto


ah, I got it now. Thanks!
Case closed!
Topic archived. No new replies allowed.