Greetings. I would like some guide and pointers from you all..and even if it is my homework..im not asking for someone to do it for me =|

QUESTION:
Develop a program that uses an array of structures to store an employee identification number(4digit), current annual salary and the result of supervisor evaluation( an integer field with 4 values.
1 = superior performance,
2 = above average,
3 = average,
4 = below average.
a) new employee salaries, assuming that employees whose performance is superior get a 4%increase, above avg 3% aavg2% and those with below avg no increase
b) the avg of new salaries summarized by perfromance error
c) the employee with highest new salary
d)the employee with lowest new salary

#include <iostream.h>

struct program
	{
		int employee_id;
		int salary;
		int eval;
		char name[30];
	};


main()
{
	int i,j;
	float sal[2];
	float new_salary(float,int);

	float sum_perform[2];
	float summarization(float,int);

	program employee[2];

	for (i = 0; i<2;i++)
	{
				cout<<"Enter your employee name: ";
				
cin>>employee[i].name;

				cout<<"Enter your employee identification number: ";
				cin>>employee[i].employee_id;

		while( employee[i].employee_id > 9999)
		{
				cout<<"ERROR!! Please enter ID again\n";
				cout<<"Enter your employee identification number: ";
				cin>>employee[i].employee_id;
		}

		cout<<"Enter current annual salary: ";
		cin>>employee[i].salary;

		cout<<"Enter result of supervisor evaluation: \n"
		 <<"    1. Superior Performance.\n"
		 <<"    2. Above Average.\n"
		 <<"    3. Average.\n"
		 <<"    4. Below Average.\n"
		 <<"     Enter rating between 1 - 4 : ";
		cin>>employee[i].eval;

		while(employee[i].eval<1 || employee[i].eval>4)
		{
				cout<<"ERROR!! Please enter result of supervisor evaluation again";
				cout<<"Enter result of supervisor evaluation: \n"
					 <<"    1. Superior Performance.\n"
					 <<"    2. Above Average.\n"
					 <<"    3. Average.\n"
					 <<"    4. Below Average.\n"
					 <<"     Enter rating between 1 - 4 : ";
				cin>>employee[i].eval;
		}

	sal[i]  = new_salary(employee[i].salary, employee[i].eval);
	sum_perform[i] = summarization(sal[i], employee[i].eval);
			}

	cout<<"\n\n";
	cout<<"\t-----------------------------------------------------\n";
	cout<<"\t **************************************************\n";
	cout<<"\t*  RRRRRRR   EEEEE  SSSSSS  UU  UU  LL     TTTTTTTT *\n";
	cout<<"\t*  RR   RR   EE     SS      UU  UU  LL        TT    *\n";
	cout<<"\t*  RRRRRRR   EEEEE  SSSSSS  UU  UU  LL        TT    *\n";
	cout<<"\t*  RR    R   EE         SS  UU  UU  LL        TT    *\n";
	cout<<"\t*  RR     R  EEEEE  SSSSSS  UUUUUU  LLLLLL    TT    *\n";
	cout<<"\t **************************************************\n";

	for (i = 0; i<2;i++)
	{
		cout<<"\n\n";
		cout<<"\t"<<"Your employee name is: ";
		cout<<employee[i].name<<endl;
		cout<<"\t"<<"Your employee identification number is: ";
			if(employee[i].employee_id < 10)
				cout<<"000"<<employee[i].employee_id<<endl;
			else if (employee[i].employee_id < 100)
				cout<<"00"<<employee[i].employee_id<<endl;
			else if(employee[i].employee_id < 1000)
				cout<<"0"<<employee[i].employee_id<<endl;
			else
				cout<<employee[i].employee_id<<endl;
		cout<<"\t"<<"Your current annual salary is: RM";
		cout<<employee[i].salary<<endl;
		cout<<"\t"<<"Result of supervisor evaluation: ";
		cout<<employee[i].eval<<endl;
		cout<<"\t"<<"Your new employee salary is: RM";
		cout<<sal[i]<<endl;
		cout<<"\t"<<"The average of new salaries: RM"<<sum_perform[i];
		cout<<"\n\n";
					}
	return 0;
}

	float new_salary(float x, int y)
	{
		float n_salary;

		if(y == 1)
			n_salary = (0.04 *x) + x;
		else if(y == 2)
			n_salary = (0.03*x) + x;
		else if(y == 3)
			n_salary = (0.02*x) + x;
		else if(y == 4)
			n_salary = x;

			return n_salary;
	}

	float summarization(float n, int b)
	{
				float sum = 0;
				int count = 0;

		if(b == 1){
			sum += n ;
			count++; }
		else if(b == 2){
			sum += n ;
			count++; }
		else if(b == 3) {
			sum += n ;
			count++;  }
		else if(b == 4) {
			sum += n ;
			count++;  }

			return sum/count;
			}

I know it is messy :( my question is.. at b) my function summarization doesn't work..i am abit stucked..i spent the whole night thinking..>_< so if someone could help me work it out i'll be grateful :cry:

Welcome to Daniweb. Regarding your Summarization Function,

float summarization(float n, int b)
{
	float sum = 0;
	int count = 0;
	if(b == 1)
	{
		sum += n ;
		count++; 
	}
	else if(b == 2)
	{
		sum += n ;
		count++; 
	}
	else if(b == 3) 
	{
		sum += n ;
		count++;  
	}
	else if(b == 4) 
	{	
		sum += n ;
		count++;  
	}

	return sum/count;
}

I see that what ever the value of b , the operation is the same.
i.e.

sum += n ;
		count++;

And as the initial values of sum and count are 0, the function can be simplified as follows.

float summarization(float n, int b)
{
         if(b >= 1 && b <=4 )
	{
	        return n;
	}
	else
	{	
                   // Error
                   return 0;
	}
}

What do you exactly mean by

summarized by perfromance error

Really sorry bout that'' was supposed to mean
Summarized by performance LeveL..so wolfpack..your way doesn't answer the question..
Erm..as in..1=superior performance..you get the new salary which is from the 1st function and sort the average based on b which is the supervisor evaluation..

Oh Okay. i think I get what you mean.
You want the average salaries the Superior Level workers worked, and so on?
Then make a small change to your summarization function.

int summarization(program EmpArray[],const  int NumberOfEmps)
{
	float Total[ 4 ] = { 0, 0, 0, 0 };
        int Count[ 4 ] = {0, 0, 0, 0 };
	for ( int i = 0 ; i < NumberOfEmps; i++ )
        {
                  Total[ EmpArray[ i ].eval - 1 ] += EmpArray[ i ].salary;
                  Count[ EmpArray[ i ].eval - 1] += 1;
         }
        if ( Count[ 0 ] != 0 )
        {
                    cout << "Avg Sup Level Salaries = " << ( Total[ 0 ] / Count[ 0 ] << endl ;
         }
         if ( Count[ 1 ] != 0 )
        {
                    cout << "Above Avg Level Salaries = " << ( Total[ 1 ] / Count[ 1 ] << endl ;
        }
        // So on until Count[ 4 ]
        return 0;
}

okay...i sort of understand it..Pardon me as I'm still rather a newbie in this..

int summarization(program EmpArray[],const int NumberOfEmps)
what is EmpArray? as in..which part of it is in my coding.. o_O

float summarization(float n, int b)
In here, i take the value n from new salary..and b from employee evaluation..

I mean..yours is completely different. Could you explain that to me abit >_<

Another thing..

Total[ EmpArray[ i ].eval - 1 ] += EmpArray[ i ].salary;
     Count[ EmpArray[ i ].eval - 1] += 1;

Why do you - 1 from the evaluation??
btw..I'm REALLY sorry for sounding stupid ><

Yeah. Stupid of me for not explaining. Sorry about that. Here is a simple version without using a Summarization Function.

See if you understand it.

#include <iostream.h>

struct program
{
	int employee_id;
	int salary;
	int eval;
	char name[30];
};

// Use constants for Arrays Sizes like below.
const int NUMBER_OF_EMPLOYEES = 2;
const int NUMBER_OF_PERFORMANCE_LEVELS = 4;
main()
{
	int i,j;
	float sal[NUMBER_OF_EMPLOYEES];
	float new_salary(float,int);

	float sum_perform[NUMBER_OF_PERFORMANCE_LEVELS]= { 0, 0, 0, 0 };
	float TotalSalary[ NUMBER_OF_PERFORMANCE_LEVELS ] = { 0, 0, 0, 0 };
	int Count[ NUMBER_OF_PERFORMANCE_LEVELS ] = { 0, 0, 0, 0 };
	/* float summarization( float,int); No need for this function*/

	program employee[ NUMBER_OF_EMPLOYEES ];
	

	for (i = 0; i<NUMBER_OF_EMPLOYEES;i++)
	{
		cout<<"Enter your employee name: ";
		cin>>employee[i].name;

		cout<<"Enter your employee identification number: ";
		cin>>employee[i].employee_id;

		while( employee[i].employee_id > 9999)
		{
			cout<<"ERROR!! Please enter ID again\n";
			cout<<"Enter your employee identification number: ";
			cin>>employee[i].employee_id;
		}

		cout<<"Enter current annual salary: ";
		cin>>employee[i].salary;

		cout<<"Enter result of supervisor evaluation: \n"
		 <<"    1. Superior Performance.\n"
		 <<"    2. Above Average.\n"
		 <<"    3. Average.\n"
		 <<"    4. Below Average.\n"
		 <<"     Enter rating between 1 - 4 : ";
		cin>>employee[i].eval;

		while(employee[i].eval<1 || employee[i].eval>4)
		{
			cout<<"ERROR!! Please enter result of supervisor evaluation again";
			cout<<"Enter result of supervisor evaluation: \n"
				 <<"    1. Superior Performance.\n"
				 <<"    2. Above Average.\n"
				 <<"    3. Average.\n"
				 <<"    4. Below Average.\n"
				 <<"     Enter rating between 1 - 4 : ";
			cin>>employee[i].eval;
		}

		sal[i]  = new_salary(employee[i].salary, employee[i].eval);
		
		TotalSalary[employee[i].eval - 1 ] += sal[i] ; // The Total Salary for a Performance Level
		Count[ employee[i].eval - 1 ] +=  1;	// The Number of Workers at a Performance Level
	}

	cout<<"\n\n";
	cout<<"\t-----------------------------------------------------\n";
	cout<<"\t **************************************************\n";
	cout<<"\t*  RRRRRRR   EEEEE  SSSSSS  UU  UU  LL     TTTTTTTT *\n";
	cout<<"\t*  RR   RR   EE     SS      UU  UU  LL        TT    *\n";
	cout<<"\t*  RRRRRRR   EEEEE  SSSSSS  UU  UU  LL        TT    *\n";
	cout<<"\t*  RR    R   EE         SS  UU  UU  LL        TT    *\n";
	cout<<"\t*  RR     R  EEEEE  SSSSSS  UUUUUU  LLLLLL    TT    *\n";
	cout<<"\t **************************************************\n";

	for (i = 0; i<NUMBER_OF_EMPLOYEES;i++)
	{
		cout<<"\n\n";
		cout<<"\t"<<"Your employee name is: ";
		cout<<employee[i].name<<endl;
		cout<<"\t"<<"Your employee identification number is: ";
			if(employee[i].employee_id < 10)
				cout<<"000"<<employee[i].employee_id<<endl;
			else if (employee[i].employee_id < 100)
				cout<<"00"<<employee[i].employee_id<<endl;
			else if(employee[i].employee_id < 1000)
				cout<<"0"<<employee[i].employee_id<<endl;
			else
				cout<<employee[i].employee_id<<endl;
		cout<<"\t"<<"Your current annual salary is: RM";
		cout<<employee[i].salary<<endl;
		cout<<"\t"<<"Result of supervisor evaluation: ";
		cout<<employee[i].eval<<endl;
		cout<<"\t"<<"Your new employee salary is: RM";
		cout<<sal[i]<<endl;
		
		//cout<<"\t"<<"The average of new salaries: RM"<<sum_perform[i];
		//cout<<"\n\n";
	}
	// Output the Average Salaries for Performance Levels
	if ( Count[ 0 ] != 0 )
	{
		cout << "Sup Level Salaries Average = " << ( Total[ 0 ] / Count[ 0 ] << endl ;
	}
	if ( Count[ 1 ] != 0 )
	{
		cout << "Above-Avg Level Salaries Average = " << ( Total[ 1 ] / Count[ 1 ] << endl ;
	}	
	if ( Count[ 2 ] != 0 )
	{
		cout << "Avg-Level Salaries Average = " << ( Total[ 2 ] / Count[ 2 ] << endl ;
	}
	if ( Count[ 3 ] != 0 )
	{
		cout << "Below-Avg Level Salaries Average = " << ( Total[ 3 ] / Count[ 3 ] << endl ;
	}
	return 0;
}

float new_salary(float x, int y)
{
	float n_salary;

	if(y == 1)
		n_salary = (0.04 *x) + x;
	else if(y == 2)
		n_salary = (0.03*x) + x;
	else if(y == 3)
		n_salary = (0.02*x) + x;
	else if(y == 4)
		n_salary = x;

		return n_salary;
}

Why I used - 1 is this.
The Performance Levels are startiing from 1and goes to 4.
But we are storing the Values in an Array, and the array elements start from the position 0.

So Superior-Level-Total will be stored in TotalSalary[ 0 ] and Above-Average-Total will be stored in TotalSalary[ 1] ...upto TotalSalary[ 3 ].

You can see that
0 = Superior-Level-Value - 1;
1 = Average-Level-Value - 1 ;
...
Hope you get it.

yup..yup its all clear now. A really big hug to you man. Now here comes another newbie question..when i add it myself and run the program..
The error Undefined symbol 'Total' in function main()...I don't get it..if TotalSalary is there..why can't i change it to Total..?

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.