Here is my code...

 #include <iostream>
#include <cstring>

using namespace std;

class employee{
public:

char name[64];
long employee_id;
float salary;
void show_employee(void);

};
};

{

cout<<"Name:"<<name<<endl;
cout<<"ID:"<<employee_id<<endl;
cout<<"Salary:"<<salary<<endl;

};
};
int main(void);
{
char str1[40]="employee worker";
char str2[40]="employee name";
char str3[40]="employee boss";
char atr4[40]="employee name";
strcpy (worker.name, "John Doe");
worker.employee_id = 12345;
worker.salary = 25000;

strcpy (boss.name, "Happy Jamsa");
boss.employee_id = 101;
boss.salary = 101101.00;

worker.show_employee();
boss.show_employee();
return 0;
};
};


it may be just something i'm missing cuz of working so hard on trying to figure it out. please can somebody tell me what is wrong with my code?

Here are the errors i get with this code...

D:\users\student\My Documents\first program\empclass.cpp|15|error: expected declaration before '}' token|

3
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by JasonHippy

On line 15 you have an extra }; that doesn't have a matching {.

Hmm, there are more problems than that in there.

If you look at the code properly, there are actually two extraneous braces in the middle of the class declaration. The two occurrences of }; should be removed at lines 14 and 15.
The brace at line 17 is the start of the body of the show_employee member function of the employee class, so you'll need to remove the semi-colon ; from the end of line 16.
Also you need to remove the semi-colon at the end of line 28 where you are defining your main() function. And there's another extraneous }; at line 46 which should also be removed!

Once you've fixed the problems mentioned above, you'll get error messages about the use of the variables 'worker' and 'boss' because you haven't declared them.

Then there are the character arrays you've declared. What are they for?
If the character arrays are meant to be instances of your class, then you are doing things drastically wrong. You need to declare them as you'd declare any other variable.
e.g.

employee worker;
employee boss;


There may be more problems with your code, but those are the most obvious ones that I can see! :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.