what is wron in the program

I have a structure that have,

Employee
{
char Last_name[25];
float Hours[5];
float H_rate;
double Gross_pay;//pay for the week
OK

I have tree funtion to capture the data fromthe structure
void initialize(Employee wor );// which ask the user to enter values for every par of the structure, but not for pay for that week.

void compute_paycheck(Employee&);//caculate the pay for

void result(Employee workers );// disply the gross pay
OK

in main funtions I have
int main()
{

Employee workers[Length]; // array of struct declared
for ( int i=0; i<Length; i++)
{
initialize( workers[i] );// funtion initilize for the variable menber passing the entired array
}

for ( int i=0; i<Length; i++)
{
compute_paycheck(workers[i]);
}

for ( int i=0; i<Length; i++)
{
result(workers[i]);
cout.precision(2);
cout.setf(ios::fixed | ios::showpoint);

}

system("pause");
return 0;
};
void initialize(Employee workers) //funtions ask the user enter value for every part of the struct
{
hsum = 0;


cout << "Enter the last name : ";
cin >> workers.Last_name;
cout << "Enter the hourly rate of pay: $ ";
cin >> workers.H_rate;

cout<< "Enter 5 day of hours worked : ";

for (int i=0; i < 5 ; i++)
{
cin>> workers.Hours[i];
hsum = hsum + workers.Hours[i];

workers.Hours[i] = hsum;
}

}
void compute_paycheck( Employee& workers)// the employee must be pased bay reference
{
float tot_hours = 0;
double G_pay;
float rate = 40;

for ( int i = 0; i < 5 ; i++)
tot_hours = tot_hours + workers.Hours[i];

if (tot_hours > rate )
G_pay = rate*workers.H_rate + (tot_hours-rate)*1.5*workers.H_rate;
else
G_pay = tot_hours*workers.H_rate;
workers.Gross_pay = G_pay;
}

void result(Employee workers) //funtions ask the user enter value for every part of the struct
{

cout<<"The employee last bame is "<<workers.Last_name<<endl;
cout<<"the Paye is "<<workers.Gross_pay<<endl;
}
/////////////////////////////////////////////////////////////////////
the program do not store for each emplyee the value. Here is the output


Enter the last name : j
Enter the hourly rate of pay: $ 10
Enter 5 day of hours worked : 3
4
5
6
7
Enter the last name : K
Enter the hourly rate of pay: $ 6
Enter 5 day of hours worked : 7
8
9
3
6
The employee last bame is ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠╠ÇfffÖÖiC
the Paye is 5.76461e+016
The employee last bame is ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠
╠╠ÇfffÖÖiC
the Paye is 57646068358394880.00
Press any key to continue . . .


Your initialize() function is taking its parameter by value, which means any changes made to the parameter
by the function are discarded when the function returns (ie, the caller does not see the modification).
Topic archived. No new replies allowed.