Write a program using two matching arrays and counts of data. Calculations of da
ID: 670483 • Letter: W
Question
Write a program using two matching arrays and counts of data. Calculations of data based on the array will be the final output to the user.
Input a list of employee names and salaries stored in parallel arrays. The salaries should be floating point numbers in increments of 100. For example, a salary of $36,000 should be input as 36.0 and a salary of $85,900 should be input as 85.9. Find the mean (average) salary and display the names and salaries of employees who earn within a range of $5,000 from the mean. In other words, if the mean salary is $45,000, all employees who earn between $40,000 and $50,000 should be displayed.
Explanation / Answer
ANSWER:
/***** C PROGRAM TO FIND MEAN SALARY AND DISPLAY THE EMPLOYEE NAME AND SALARY WITHIN THE RANGE***********/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
//DECLARE THE PARALLEL ARRAYS FOR SALARIES AND NAME
float salaries[10];
char *emp_Names[10];
int EMPn,k1,k2;
float tot_SAL=0,meanSAL;
//GET THE NO OF EMPLOYEES
printf("ENTR THE NO OF EMPLOYEES:");
scanf("%d",&EMPn);
printf("eNTER EMPLOYEE NAME AND SALARY:");
//GET EMPLOYEE NAME AND SALARY
for(k1=0;k1<EMPn;k1++)
{
scanf("%f%s",&salaries[k1],emp_Names[k1]);
}
for(k1=0;k1<EMPn;k1++)
{
tot_SAL+=(salaries[k1]*1000);
}
//FIND THE MEAN
meanSAL=tot_SAL/EMPn;
//PRINT THE EMPLOYEE NAME AND SALARY WHOSE SALARY IS WITHIN HTE AVERAGE
printf("EMPLOYEES WHOSE SALARY IS IN THE RANGE OF MEAN:");
for(k1=0;k1<EMPn;k1++)
{
if((salaries[k1]*1000)>=(meanSAL-5000)&&(salaries[k1]*1000)<=(meanSAL+5000))
{
printf("NAME: %s sALARY:%f",emp_Names[k1],salaries[k1]*1000);
}
}
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.