Use a single-subscripted array to solve the following problem. A company pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9 percent of their gross sales for that week. For example, a salesperson who grosses $3000 in sales in a week receives $200 plus 9 percent of $3000, or a total of $470. Write a C program (using an array of counters) that determines how many of the salespeople earned salaries in each of the following ranges (assume that each salesperson’s salary is truncated to an integer amount):
a) $200–299
b) $300–399
c) $400–499
d) $500–599
e) $600–699
f) $700–799
g) $800–899
h) $900–999
i) $1000 and over
#include <stdio.h>
int main(void){
int n;
printf("Enter the number of salespeople you have:");
scanf("%d",&n);
int salespeople[n];
for(int i=0;i<n;i++){
printf("Enter employee's #%d weekly sales: ",i+1);
scanf("%d", &salespeople[i]);
}
int counters[7];
for(int i =0;i<9;i++) counters[i]=0;
for(int i =0, salary=0; i<n;i++){
salary= 200+salespeople[i]*0.09;
if(salary<0) continue;
if(salary==0) {counters[0]++; continue;}
if(salary>1000){
counters[7]++;}
else{
counters[(salary%1000)/100-2]++;}
}
for(int i =0; i<9;i++){
printf("$%d-%d : %d\n",(i+2)*100,(i+2)*100,counters[i]);
}
return 0;
}
Comments
Leave a comment