(Sales Commissions) Use a single-subscripted array to solve the following proble
ID: 3654275 • Letter: #
Question
(Sales Commissions) Use a single-subscripted array to solve the following problem. A com- pany pays its salespeople on a commission basis. The salespeople receive $200 per week plus 9% of their gross sales for that week. For example, a salesperson who grosses $3000 in sales in a week re- ceives $200 plus 9% 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 salespersonExplanation / Answer
#include /* Function prototypes */ void getsales(int count[]); void printranges(int count[]); 13 int main(void) 14 { 15 /* Declare variables and initialize variables to 0 */ 16 int count[11] = {0, /* not used */ 17 0, /* not used */ 18 0, /* $200-$299 */ 19 0, /* $300-$399 */ 20 0, /* $400-$499 */ 21 0, /* $500-$599 */ 22 0, /* $600-$699 */ 23 0, /* $700-$799 */ 24 0, /* $800-$899 */ 25 0, /* $900-$999 */ 26 0}; /* $1000 and over */ 27 28 /* Call function getsales() to get employee's weekly gross sales */ 29 getsales(count); 30 31 /* Call function printranges() to print the table of the number of employees in the different salary ranges */ 32 printranges(count); 33 34 return 0; 35 } 36 37 /**********************getsales************************** 38 * Description: This function keeps prompting the user 39 * to input employees' weekly gross sales 40 * until they press control-d 41 * Parameters: integer array to hold the count of 42 * employee's in the different salary 43 * ranges 44 * Return: none 45 ********************************************************/ 46 void getsales(int count[]) 47 { 48 /* Declare variables and initialize variables to 0 */ 49 int salary = 0; 50 float sales = 0; 51 52 /* Prompt user for an employee's weekly gross sales, user will enter control-d to end entries */ 53 printf ("Enter an employee's weekly sales (control-d to end): "); 54 55 /* While not end of input */ 56 while (scanf("%f", &sales) != EOF) 57 { 58 59 /* Calculate this latest employee's weekly salary */ 60 salary = 200 + .09 * sales; 61 62 /* Determine and increment the corresponding array element for the salary range */ 63 if (salary >= 1000) 64 { 65 count[10]++; 66 } 67 else if (salary >= 200) 68 { 69 count[salary / 100]++; 70 } 71 72 /* Prompt user for an integer value, user will enter control-d to end entries */ 73 printf ("Enter an employee's weekly sales (control-d to end): "); 74 } 75 } 76 77 /**********************printranges*********************** 78 * Description: This function prints the number of 79 * employees in each of the nine different 80 * salary ranges 81 * Parameters: integer array that holds the count of 82 * employee's in the different salary 83 * ranges 84 * Return: none 85 ********************************************************/ 86 void printranges(int count[]) 87 { 88 int i; 89 90 printf("Employees in salary range: "); 91 for (i = 2; i < 10; i++) 92 { 93 printf("$%d00 - $%d99: %d ", i, i, count[i]); 94 } 95 printf("$1000 and over: %d ", count[10]); 96 }Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.