Answer to Question #343561 in C++ for James

Question #343561

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 




1
Expert's answer
2022-05-22T18:10:36-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS