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: