hi plzzz i need ahelp to know what rong with this program
the problem is in the display function
the code

#include <iostream.h>
#include<string.h>
class Employee
{
private:
char	number[55], name [55], salary[55];
public:
	Employee();
	~Employee();
void set();
void display ();
};
Employee::Employee()
{
	cout<<"The constructor called"<<endl;
}
Employee::~Employee()
{
	cout<<"the object deleted"<<endl;
}

void Employee::set()
{
	int i,j;
	
	for( i=0;i<3;i++){
		for(j=0;j<i;j++){
	cout<<"Enter the employee name"<<endl;
cin>>name;

cout<<"Enter the employee number"<<endl;
cin>>number;
cout<<"Enter the employee salary"<<endl;
cin>>salary;
}}}
void Employee::display()
{
	for(int i=0;i<3;i++)
	{
cout<<"employee name is:"<<name[i]<<endl;
cout<<"employee number is:"<<number[i]<<endl;
cout<<"employee salary is:"<<salary[i]<<endl;
}}
void main()
{
	Employee a;	
	a. set();
	a. display();
		
}

<< moderator edit: added code tags: [code][/code] >>

hi plzzz i need ahelp to know what rong with this program
the problem is in the display function
the code

what do you think is wrong with it? Do you get compiler errors? If yes, what errors? Or are there runtime errors -- what are they.

Function display() is attempting to treat each of the class objects m(name, number and salary) as if they were three of each -- there is only one of each. remove the loop and the index into each array

You need to put your code in [ code ] [ /code ] tags.

I ran your code and see that it only outputs one letter for each entry. With a C-string (array of characters) you may have to write a for loop that "hits" each character to get it to print out properly.

You need to put your code in [ code ] [ /code ] tags.

I ran your code and see that it only outputs one letter for each entry. With a C-string (array of characters) you may have to write a for loop that "hits" each character to get it to print out properly.

THANX but can you write the for loop please

Ancient Dragon
i have no compler error my error is in the out put
thanx

I want the display function that show me the name,number,and salary for each employee
I have just 3 employee

if you have 3 employees, then you need to allocate 3 Employee objects, not one as you did in main(). One Employee object only holds the information for one employee.
The display function should like like this. Also remove that loop from the Set() function too.

void Employee::display()
{
cout<<"employee name is:"<<name<<endl;
cout<<"employee number is:"<<number<<endl;
cout<<"employee salary is:"<<salary<<endl;
}

and main like this

void main()
{
	Employee a[3];	
        for(int i = 0; i < 3;i++)
        {

   	   a[i]. set();
	   a[i]. display();
	}
}

or if you only want one Employe object when you only want to work with one employee at a time.

void main()
{
        for(int i = 0; i < 3;i++)
        {
	   Employee a;	
   	   a. set();
	   a. display();
	}
}

final suggestion: Since this is a c++ program, not C program, use c++ std::string class if your instructor will allow it.

std::string	number, name, salary;

Ancient Dragon
thanx alot

THANX but can you write the for loop please

I could, but I charge $1000 for each line of code I write for someone else.

I'll explain the structure so you can write it yourself:

for ({}variable{}, {}loop exit condition{}, {}increment/decrement{})
  {
  {}statement block{}
  }

{}variable{}
This is either a variable you declare here or one that's been declare already in your program. (You just want to increment it in the for loop for some reason.)

{}loop exit condition{}
This is the condition the system checks for to know when to exit the loop. Using equality usually doesn't work, you must use a comparison (<, >, <=, >=).

{}increment{}
This is an expression that tells the loop counter what to do. Usually you want to count up by one, so you say i++, but if you wanted to count down you'd say i-- (if your variable is i.

{}statement block{}
In your case, you'd probably want to cout your variable subscripted with the character position. I.E. cout << a[1] << a[2] etc.

Note the two braces ({}) around each segment are not part of the language, they're there to make it easier for you, the human, to understand.

If you use the string as suggested above, you don't have to mess with output like this.

thanks i will try

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.