works without errors!! but stops in the output!!

okay guys, this my program about employee management system. I had earlier posted this coding asking to clear the errors. Now its working fine without errors, but then in the result area ,the search option doesn't proceed after I give in the required input, I mean it stops and goes to yes or no question after this step. So please could anyone check out what's wrong???

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int en;
char empname[20];
char empdesig[30];
int yj;
int basal;
char qual[50];
int dob;
int age;
int empid[5];
int cne();
int edit();
int sae();
int mse();
int dis();
struct empdet
{
int en;
char empname[20];
char empdesig[30];
int yj;
int basal;
char qual[50];
int dob;
int age;
}worker;
int main()
{
char choice;
do
{
int n;
cout<<"**********************************\n";
cout<<"--EMPLOYMENT MANAGEMENT SYSTEM--\n";
cout<<"***********************************\n";
cout<<"1.Create New Employee details\n";
cout<<"2.Edit an employee\n";
cout<<"3.Search an employee\n";
cout<<"4.Monthly Salary of an employee\n";
cout<<"5.display\n";
cout<<"6.Exit\n";
cin>>n;
switch(n)
{
case 1: cne();
break;
case 2: edit();
break;
case 3: sae();
break;
case 4: mse();
break;
case 5: dis();
break;
case 6:exit(0);
break;
default:
cout<<"Invalid input! Get lost!!";
}
cout<<"\n Do you want to continue:(Y or N)";
cout<<"\n enter your choice:";
cin>>choice;
if(choice=='y'||choice=='Y');
{
cout<<"Again enter choice:";
}
}while(choice=='y'||choice=='Y');
return 0;
}
int cne()
{
cout<<"Enter the Employee no:";
cin>>worker.en;
cout<<"Enter the Employee Name:";
cin>>worker.empname;
cout<<"Enter Employee Designation:";
cin>>worker.empdesig;
cout<<"Enter the year joined:";
cin>>worker.yj;
cout<<"Enter Employee's Qualification:";
cin>>worker.qual;
cout<<"Enter Date of Birth:";
cin>>worker.dob;
cout<<"Enter Employee's Age:";
cin>>worker.age;
return 0;
}
int edit()
{
cout<<"under construction";
return 0;
}
int sae()
{
cout<<"You can search only by giving in the employee ID\n";
cout<<"Enter Employee ID:";
cin>>empid[5];
for(int i=0;i<=en-1;i++)
{
if(worker.en=='empid')
{
cout<<"------------------------------\n";
cout<<worker.empname;
cout<<worker.empdesig;
cout<<worker.yj;
cout<<worker.basal;
cout<<worker.qual;
cout<<worker.dob;
cout<<worker.age;
}
}
return 0;
}
int mse()
{
cout<<"wait!";
return 0;
}
int dis()
{
cout<<"Employee no:\n";
cout<<worker.en;cout<<"\n";
cout<<"Employee Name:\n";
cout<<worker.empname;cout<<"\n";
cout<<"Employee Designation:\n";
cout<<worker.empdesig;cout<<"\n";
cout<<"year joined:\n";
cout<<worker.yj;cout<<"\n";
cout<<"Employee's Qualification:\n";
cout<<worker.qual;cout<<"\n";
cout<<"Date of Birth:\n";
cout<<worker.dob;cout<<"\n";
cout<<"Employee's Age:\n";
cout<<worker.age;cout<<"\n";
return 0;
}
By "search option" I assume you're referring to sae. sae should not compile. 'empid' is not a valid character literal. (And worker.en is an id number, not a character or string.)

Also, empid is an array with 5 elements. std::cin >> empid[5] attempts to read a character into the 6th element of your 5 element array. But, again, since the id is a number and you store it as such, you probably don't want to extract a character or string for comparison.

And, the idea of a "searching" when you only ever have one 'worker' seems a little off.
Last edited on
Okay, but then I am a beginner in programming of C++.And so I don't know about storing more than 2 employees at a time. Moreover I didn't understand what ever you have explained in the above reply. So if possible could you give me a clear and easy idea on how to search an employee, like the basic behind this particular concept?? But only if its possible. Please do get me through this topic.
guys! no one has replied for this message yet! please guys, do get me through this program, because I am a Beginner.
Hope you guys would respond this time..
cin>>empid[5];
This is a 5-element array. You will go out of bounds here. You probably shouldn't be reading in characters if the employee ID is just an integer.

Just read in one integer. You're searching for only one employee, right? So, just read in one integer and compare it to "employee.en".

Have you worked on this since the 7th?
Last edited on
You haven't actually declared any variables of type 'worker'

The type name is empdet. worker is an instance of empdet.

@ OP: If you can't be bothered to review the material you've learned thus far (or google or find a tutorial) and modify or at least attempt to modify the code you present based on the feedback you receive, you aren't going find this place is much help to you.
Last edited on
Sorry, I skimmed too quickly and missed that. It's kind of hard to read with all the code smashed to the left like that. I didn't paste it into my text editor. I'll edit.

@OP: Sometimes sketching out the structure of your program helps. That's how I begin my projects.
However, you can't expect us to do it for you. Projects and homework are supposed to be a learning experience.
To,
Jay;

Yes, I do require more than one worker. And this my first year working with C++!!
The problem is I don't understand what you are trying to convey. Just give an exact clue about what is to be done at which place, and I believe I can do the rest.
Well, C++ allows has many containers that will allow you to store multiple instances of the same type. You could check out std::vector
That is usually my default choice for a container

http://www.cplusplus.com/reference/vector/vector/

You could use that to store multiple employees.
You could create a new instance of 'worker' when you add a new worker and push it back into a vector to store it.
Topic archived. No new replies allowed.