473,325 Members | 2,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Need help with error thrown by compiler

Error message is identifier expected and declaration terminated incorrectly.

//to define a class Employee
#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<conio.h>

class cEmp
{
private:

int eid;
char ename[10];
char dname[10];
float sal;

public:

cEmp();
cEmp(int,char*,char*,float);
void accept();
void display();
float getsal();
int getid();
};

cEmp::cEmp()
{
eid=0;
strcpy(ename,"/0");
strcpy(dname,"/0");
sal=0;
}

cEmp::cEmp(int,char*,char*,float)
{
int id;
float s;
char n[10],d[10];
eid=id;
strcpy(ename,n);
strcpy(dname,d);
sal=s;

}
cEmp::void accept() //Error in this line<<<<<<<<<<<<<<<
{
cout<<"Enter empoyee ID:";
cin>>eid;
cout<<"Enter employee name:";
gets(ename);
cout<<"Enter department name";
gets(dname);
cout<<"Enter employee salary:";
cin>>sal;
}

cEmp::void display()
{
cout<<"\nEmployee ID:"<<eid;
cout<<"\nEmployee name:"<<ename;
cout<<"\nDepartment name"<<dname;
cout<<"\nEmployee salary"<<sal;
}

cEmp::void getid()
{
return eid;
}

cEmp::void getsal()
{
return sal;
}

void main()
{
clrscr();
do
{
cout<<"\t\tMenu";
cout<<"\n\n\t1.\tDisplay all the employees' info.";
cout<<"\n\n\t2.\tDisplay specific employes' info.";
cout<<"\n\n\t3.\tDisplay employee with max salary.";
cout<<"\n\n\tEnter choice:";
int n,i,a;
cin>>a;
switch(a)
{
case 1:
for(i=0;i<n;i++)
c[i].display();
break;
case 2:
cout<<"Enter ID:";
int x;
cin>>x;
for(i=0;i<n;i++)
if(c[i].getid()==x)
c[i].display();
break;
case 3:
float max=0;
for(i=0;i<n;i++)
if(c[i].getsal()>max)
max=c[i].getsal();
for(i=0;i<n;i++)
if(c[i].getsal()==max)
c[i].display();
break;
}
cout<<"\nDo you want to continue?(y/n):";
char y;
cin>>y;

}
while(y=='y');
{
getch();
}
return();
}
Jan 30 '15 #1

✓ answered by weaknessforcats

The return types of several of the member functions have been removed. They need to be put back and they need to match the function prototype in the class declaration. Remember, any time a function returns a value, the function return type cannot be void.

Where is this c array? :
Expand|Select|Wrap|Line Numbers
  1. switch (a)
  2.         {
  3.         case 1:
  4.             for (i = 0; i<n; i++)
  5.                 c[i].display();
  6.             break;
  7.         case 2:
  8.             cout << "Enter ID:";
  9.             int x;
  10.             cin >> x;
  11.             for (i = 0; i<n; i++)
  12.             if (c[i].getid() == x)
  13.                 c[i].display();
  14.             break;
  15.  
  16.  
The char y is inside the braces and the while is outside the braces:

Expand|Select|Wrap|Line Numbers
  1.         char y;
  2.         cin >> y;
  3.  
  4.     } while (y == 'y'); <---y has been destroyed.
You cannot use variables inside braces from outside the braces. Instead you define variables outside the braces and use them from inside nested braces. Since the nested braces are still inside the outer braces, the variables can be used because they are still inside the outer braces.

7 1694
I can't find any reason for this error as all the braces are in the appropriate positions. please help thanks in advance.
Jan 30 '15 #2
weaknessforcats
9,208 Expert Mod 8TB
The name of the function is cEmp::accept().

So this is correct:

Expand|Select|Wrap|Line Numbers
  1. void cEmp::accept()
  2. {
  3. etc...
and not:
Expand|Select|Wrap|Line Numbers
  1.  cEmp::void accept()
  2. {
  3. etc...
This error occurs in several places. Also, in some places the return value of the function in the class definition does not match the return value in the function definition.

Hopefully, this is enough to get you unstuck.
Jan 30 '15 #3
When I remove void from the function I get a host of errors by the compiler saying that the
functions are not member functions of the class cEmp
errors- cEmp::accept()
  1. accept() is not a member of cEmp
  2. display(), "
  3. getid(), "
  4. getsal(), "
  5. undefined symbol c at line 91
  6. undefined symbol y at line 116
  7. expression syntax at line 120
Jan 30 '15 #4
also a warning stating that max is assigned to a value that is never used.
Jan 30 '15 #5
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<conio.h>
  5.  
  6. class cEmp
  7. {
  8.      private:
  9.  
  10.      int eid;
  11.      char ename[10];
  12.      char dname[10];
  13.      float sal;
  14.  
  15.      public:
  16.  
  17.      cEmp();
  18.      cEmp(int,char*,char*,float);
  19.      void accept();
  20.      void display();
  21.      float getsal();
  22.      int getid();
  23. };
  24.  
  25. cEmp::cEmp()
  26. {
  27.      eid=0;
  28.      strcpy(ename,"/0");
  29.      strcpy(dname,"/0");
  30.      sal=0;
  31. }
  32.  
  33. cEmp::cEmp(int,char*,char*,float)
  34. {
  35.      int id;
  36.      float s;
  37.      char n[10],d[10];
  38.      eid=id;
  39.      strcpy(ename,n);
  40.      strcpy(dname,d);
  41.      sal=s;
  42.  
  43. }
  44. cEmp::accept()
  45. {
  46.      cout<<"Enter empoyee ID:";
  47.      cin>>eid;
  48.      cout<<"Enter employee name:";
  49.      gets(ename);
  50.      cout<<"Enter department name";
  51.      gets(dname);
  52.      cout<<"Enter employee salary:";
  53.      cin>>sal;
  54. }
  55.  
  56. cEmp::display()
  57. {
  58.      cout<<"\nEmployee ID:"<<eid;
  59.      cout<<"\nEmployee name:"<<ename;
  60.      cout<<"\nDepartment name"<<dname;
  61.      cout<<"\nEmployee salary"<<sal;
  62. }
  63.  
  64. cEmp::getid()
  65. {
  66.      return eid;
  67. }
  68.  
  69. cEmp::getsal()
  70. {
  71.      return sal;
  72. }
  73.  
  74. void main()
  75. {
  76.      clrscr();
  77. do
  78. {
  79.      cout<<"\t\tMenu";
  80.      cout<<"\n\n\t1.\tDisplay all the employees' info.";
  81.      cout<<"\n\n\t2.\tDisplay specific employes' info.";
  82.      cout<<"\n\n\t3.\tDisplay employee with max salary.";
  83.      cout<<"\n\n\tEnter choice:";
  84.      int n,i,a;
  85.      cin>>a;
  86.      switch(a)
  87.      {
  88.       case 1:
  89.          for(i=0;i<n;i++)
  90.          c[i].display();
  91.          break;
  92.       case 2:
  93.          cout<<"Enter ID:";
  94.          int x;
  95.          cin>>x;
  96.          for(i=0;i<n;i++)
  97.               if(c[i].getid()==x)
  98.                c[i].display();
  99.          break;
  100.       case 3:
  101.         float max=0;
  102.         for(i=0;i<n;i++)
  103.              if(c[i].getsal()>max)
  104.               max=c[i].getsal();
  105.         for(i=0;i<n;i++)
  106.              if(c[i].getsal()==max)
  107.              c[i].display();
  108.         break;
  109.      }
  110.      cout<<"\nDo you want to continue?(y/n):";
  111.      char y;
  112.      cin>>y;
  113.  
  114.      }
  115.      while(y=='y');
  116.      {
  117.      getch();
  118.      }
  119.      return();
  120. }
  121.  
here's the code wrapped, I know the indentation is a little off. Thanks in advance, really appreciate it!
Jan 30 '15 #6
weaknessforcats
9,208 Expert Mod 8TB
The return types of several of the member functions have been removed. They need to be put back and they need to match the function prototype in the class declaration. Remember, any time a function returns a value, the function return type cannot be void.

Where is this c array? :
Expand|Select|Wrap|Line Numbers
  1. switch (a)
  2.         {
  3.         case 1:
  4.             for (i = 0; i<n; i++)
  5.                 c[i].display();
  6.             break;
  7.         case 2:
  8.             cout << "Enter ID:";
  9.             int x;
  10.             cin >> x;
  11.             for (i = 0; i<n; i++)
  12.             if (c[i].getid() == x)
  13.                 c[i].display();
  14.             break;
  15.  
  16.  
The char y is inside the braces and the while is outside the braces:

Expand|Select|Wrap|Line Numbers
  1.         char y;
  2.         cin >> y;
  3.  
  4.     } while (y == 'y'); <---y has been destroyed.
You cannot use variables inside braces from outside the braces. Instead you define variables outside the braces and use them from inside nested braces. Since the nested braces are still inside the outer braces, the variables can be used because they are still inside the outer braces.
Jan 30 '15 #7
Aah got it, thanks again
Jan 30 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mike Fisher | last post by:
I'm seeing an error when I try to run/debug a web service. Although it doesn't happen every time, it does occur more than half of the times I hit F5. It appears to be returned by the the JIT...
1
by: Marco Gerlach | last post by:
Hello, on one of our customers servers we get following error on first ASPX-page: An error occurred while try to load the string resources (GetModuleHandle failed with error -2147023888) ...
1
by: Razzie | last post by:
Hi all, I was working on a little project, worked fine, but now all of a sudden I get: The compiler failed with error code -1073741502 as an error message (when running the site, not...
25
by: Mark | last post by:
I'm just starting out in an introductory ASP.Net course, and am trying to run a simple program but keeping getting an error. I'm running XP, have installed Internet Information Services (5.1) ,...
2
by: Roger Wang | last post by:
HELP!!!! We have got a W2k server running IIS5 with .NET framework 1.1 and .NET framework SP1. All ASP.NET applications cannot run on this box. It all returned with the same error: ...
0
by: jeffpriz | last post by:
We've got an issue here where we regularly receive an error page with the message "Compiler Error Message: The compiler failed with error code 2000." when we begin debug on our projects. The...
0
by: Ram | last post by:
Hey, I have a Windows 2000 Advanced Server SP4 with Framework 1.1 installed. I have an ASPNet website that every now and then I get the following error: "Compiler Error Message: The compiler...
1
by: bhanupoornakumar | last post by:
Hi .. when i am setting a website i am getting the following error.. The compiler failed with error code -1073741819. This is the full error .. u can see below. Compilation Error ...
14
Frinavale
by: Frinavale | last post by:
I've been trying to test my web application using Internet Explorer 8 (release candidate 1) and have been experiencing some major problems. I'm hoping you can help me with this one. I have a...
1
by: kmsandeep17 | last post by:
when i host my site on go daddy it give error Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.