how can i fix the random symbols im getting when i pass a varriable through my constructor

I have updated my constructor now i dont get compiler errors but when i run it i get random symbols where a name should be. The issue is with the second constructor

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
  class Employee
{
public:
  Employee()
  {
  	char person[]="None";
  	strcpy (name, person);
  	idNum=1000;
  	salary=0;
  };
  Employee(const char x[], int id, double sal)
  {
	strcpy (name,x);
  	idNum=id;
  	salary=sal;
  };
 
  void printEmp()
  	{
  		for (int x=0;x<26;x++)
  		{
  			cout<<name[25];
		}
  		cout<<"ID: "<<idNum;
  		cout<<"         Salary: "<<salary;
  	};
  void increaseSalary( double more)
  {
	if (more>0)
	{
		salary=salary+more;
	}
	else
	{
		cout<<"Error: the salary cannot be increased";
	}
  };

  void setIDnum( int newIDnum)
  {
  	if (newIDnum<1000||newIDnum>9999999)
  	{
		cout<<"Error: the new identification number is invalid. It will be ste to 1000";
  		idNum=1000;
	}
	else
	{
		idNum=newIDnum;
	}
  };
  void setSalary( double newSalary)
  {
  	if(newSalary<=0)
  	{
  		cout<<"Error: the passed in salary is invalid. The salary will be set to 0.00";
  		salary=0.00;
	}
	else
	{
		salary=newSalary;
	}
  };

  int getIDnum()
  {
  	return idNum;
  };
  double getSalary()
  {
  	return salary;
  };

private:
  char name[25];
  int idNum;
  double salary;
};
//Employee Class Definition


int main()
{

//Create 5 Employee objects.


//First Employee

//Create the object
Employee e1= Employee( "Matthew Lyon", 1704663, 678367732.40);
My compiler wrote:
cout<<name[25]; // warning: array subscript is above array bounds [-Warray-bounds]
Last edited on
Topic archived. No new replies allowed.