errors when compiling

Pages: 12
When compiling I get a bunch of different errors such as "string does not name type" in EmployeeInfo.h also declaration does not declare anything in EmployeeInfo.h, also in payroll.cpp, Struct employee has no member named firstname and lastname, and other errors, I don't see where my errors are, please someone help me lol.
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
  (Employeeinfo.h)
struct Date
{ 
    int month;
    int day;
    int year;
};

struct EmployeeInfo
{
int id;
string firstname;
string lastname;
Date birthday;
Date datehired;
double payrate;
int hours;
};

(payroll.cpp)
#include <iostream>
#include <iomanip>
#include <string>

#include "Employeeinfo.h"
using namespace std;
int main()
{
EmployeeInfo employee;
double grosspay, tax, netpay, totalgp=0, totaltax=0, count=0;
   cin  >>  employee.id  >> employee.firstname  >>  employee.lastname >> employee.birthday.month>>employee.birthday.day>>employee.birthday.year>>employee.datehired>>employee.payrate>>employee.hours;
while (count<10)
{
grosspay = employee.payrate * employee.hours;
if(grosspay>=1000)
tax = .25*grosspay;

else
{
	tax = .18*grosspay;
}
	netpay = grosspay - tax;
count++;
totalgp+= grosspay;
totaltax+= tax;
cout<<employee.id << employee.firstname << employee.lastname << employee.birthday.month <<employee.birthday.day<<employee.birthday.year<< employee.datehired << employee.payrate << employee.hours << tax << netpay << totalgp << totaltax<<endl;
return 0; 
}

Did you #include <string> ?
Yes, when compiling payroll.cpp, it has #include<string>
You can't just include headers whenever and wherever you feel like it, you need to include them before they're used. #include <string> in your EmployeeInfo.h file.
@LB I just included #include<string> to my EmployeeInfo.h file and still getting that "string does not name type" error in my EmployeeInfo.h file
Last edited on
Anyone else see any mistakes ?
Did you move using namespace std to the top? All of your libraries you are using need to be declared at the top of the file.
@Mr D moving it before #include<Employee.h> didn't help, it actually gave me a bigger error than I had before.
All your includes should be at the top, followed by your using namespace std.
@Mr D I changed my source file to
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Employeeinfo.h"
(changed position of using namespace std)
I eliminated the string errors, but not I got a really really really long syntax error when im compiling it on unix. So is it just my code in general that is the problem ?
1
2
3
4
5
#include <iostream>
#include <iomanip>
#include <string>
using namespace std; 
#include "Employeeinfo.h" // All your includes, followed by using namespace std, this is an include, isn't it? Switch this. 


Without knowing what the error code is, I can't help you. But, putting ALL of the includes FIRST, followed by the namespace should solve your issue.
Last edited on
@Mr D well that was what I had to begin with, I just changed it to this after you told me to change using namespace std to the top.
All your includes should be at the top, followed by your using namespace std.
1
2
3
4
5
#include <iostream>
#include <iomanip>
#include <string>
#include "Employeeinfo.h"
using namespace std;
@Mr D again, that's what I had to begin with...
Without knowing what the error code is, I can't help you.

Please, post your new code followed by the error code.
Last edited on
if you dont want to declare using namespace std;
you should write std::string if you declare a string
this will fix it
also, putting all includes first doesn't actually solve the issue because I would still get the string error, but after making the header file last, i would eliminate that error.
Lorence30 is correct, but it won't fix your error. Declaring using namespace std brings in the entire namespace and is considered bad practice, whereas just typing using std::string at the top of the file ( under your includes and header files ) specifies that you ONLY want to use the string of the standard library, which in effect is the same as typing std::string every time you want to use it, except it saves you some typing.
Last edited on
Just so everyone knows this is being compiled on Unix, NOT C++.
Without posting your new code, and your error message, we CAN NOT help you.
Pages: 12