Undeclared identifier help, can't figure out what's wrong

It pops up and shows these messages when compiling, but I couldn't figure out what's wrong, can anyone help me? I just want to write a program where user types in the gross pay and it calculates the amount and outputs that.
It shows these errors:

(26): error C2146: syntax error : missing ';' before identifier 'endl'
(26): warning C4551: function call missing argument list
(27): error C2065: 'amount' : undeclared identifier
(28): error C2065: 'NetPay' : undeclared identifier
(28): error C2065: 'amount' : undeclared identifier
(28): error C2065: 'amount' : undeclared identifier
(28): error C2065: 'federalTax' : undeclared identifier
(28): error C2065: 'amount' : undeclared identifier
(28): error C2065: 'stateTax' : undeclared identifier
(28): error C2065: 'amount' : undeclared identifier
(28): error C2065: 'socialSecurityAndMedicareTax' : undeclared identifier
(28): error C2065: 'healthInsurance' : undeclared identifier
(29): error C2065: 'NetPay' : undeclared identifier
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
  // Paycheck project
#include <iostream>
#include <iomanip> 
#include <string>
using namespace std;

int main()
{ 
	string firstName,
		lastName,
		month,
		year,
	double amount,
	const double federalTax = .15,
		stateTax = .035,
		socialSecurityAndMedicareTax = .085,
		healthInsurance = 75;
	cout << "Please enter your first name." << endl;
	cin >> firstName >> endl;
	cout << "Please enter your last name." << endl;
	cin >> lastName >> endl;
	cout << "Please eneter the month of your paycheck." << endl;
	cin >> month >> endl;
	cout << "Please enter the year of your paycheck." << endl;
	cin >> year >> endl;
	cout << "Please enter the gross pay of your paycheck." endl;
	cin >> amount >> endl;
	NetPay = amount-(amount*federalTax)-(amount*stateTax)-(amount*socialSecurityAndMedicareTax)-(healthInsurance);
	cout << setprecision(2) << fixed << NetPay << endl;
		
	return 0;
}


Thanks for help in advance!
Last edited on
closed account (E0p9LyTq)
Always declare variables on separate lines. cin and endl don't work together, endl is only used with cout. You didn't declare what type NetPay is.

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
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

int main()
{
   string firstName;
   string lastName;
   string month;
   string  year;
   double amount;
   const double federalTax = .15;
   const double stateTax = .035;
   const double socialSecurityAndMedicareTax = .085;
   const double healthInsurance = 75;
   
   cout << "Please enter your first name." << endl;
   cin >> firstName;

   cout << "Please enter your last name." << endl;
   cin >> lastName;

   cout << "Please eneter the month of your paycheck." << endl;
   cin >> month;

   cout << "Please enter the year of your paycheck." << endl;
   cin >> year;

   cout << "Please enter the gross pay of your paycheck." << endl;
   cin >> amount;

   double NetPay = amount-(amount*federalTax)-(amount*stateTax)-amount*socialSecurityAndMedicareTax)-(healthInsurance);
   cout << setprecision(2) << fixed << NetPay << endl;

   return 0;
}
Thanks Furry Guy! That solved my problem! Also, can you explain what does const do? I can't seem to find an answer in the terms that I understand. All I know was that if I use const, the users can't change the numbers or something? Thanks again!
It declares the variable as constant. After you set those values, they can't be changed. It is useful as a safety measure to prevent an accident like changing the healthInsurance value at some point and resulting in inconsistent results throughout your program.
Topic archived. No new replies allowed.