Need Help!!!! Instructor can't figure it out either!!!!

#include <iostream>
#include <string>

using namespace std;

int main(void)

{
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()
{
employee worker;
employee boss;

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();
}


i keep getting these errors!!!!

In function 'int main()':
error: expected '}' at end of input
In member function 'int main()::employee::main()':
error: 'strcpy' was not declared in this scope
warning: no return statement in function returning non-void [-Wreturn-type]
In function 'int main()':
error: expected unqualified-id at end of input
error: expected '}' at end of input
Last edited on
Why do you have function main defined twice?
You have two declarations for main. Lose the top one, including your opening brace.

Add a closing brace to your show_employee function.

Include the cstring header for strcpy.

Get a new instructor.
If you will change header <string> to <cstring> and add two closing braces the code will be compiled without any error (I think so).:)


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 <cstring>
 
using namespace std;
 
int main(void)
{
   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()
      {
         employee worker;
         employee boss;
 
         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();
     }
   };
} 


And if you add before the last closing brace statement

employee().main();

you will even see the result!:)

I am sorry member function main shall either return int or be defined as void. So the result code will be the following

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
#include <iostream>
#include <cstring>
 
using namespace std;
 
int main(void)
{
   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;
       };
 
      void main() /* Though the C++ Standard suppresses to define main as void we will do that! */
      {
         employee worker;
         employee boss;
 
         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();
     }
   };

   employee().main();
} 

Last edited on
thank you so much!!!! that helped to get rid of the errors but i still had a warning about the return. we little about it but mostly have been trying to get this damn code to work. now i have a new question... how can i see what it would look like after being built? i got it built and told it to run but all i get is the little black screen and it looks like this:


Process returned 0 (0x0) execution time : 0.083 s
Press any key to continue.

is that how it is supposed to look or did i not something or do something wrong?
It was a joke. The correct code shall look the following way

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
#include <iostream>
#include <cstring>
#include <cstdlib>
 
using namespace std;
 
int main()
{
   class employee{
   public:
       char name[64];
       long employee_id;
       float salary;
       void show_employee() const
       {
          cout<<"Name:"<<name<<endl;
          cout<<"Id:"<<employee_id<<endl;
          cout<<"Salary:"<<salary<<endl;
       }
   };
 
   employee worker;
   employee boss;
 
   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();

   system( "Pause" );

   return 0;   
}
Last edited on
Topic archived. No new replies allowed.