Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming in C language to be run on code blocks 3. (Two-dimension Array) A co

ID: 3724824 • Letter: P

Question

Programming in C language to be run on code blocks

3. (Two-dimension Array) A company that pays their employees on a commission basis has contracted you to write a program that will calculate how much they owe their employees. The company has 4 employees and sells s different products. The products and the commission each employee receives from selling the products is given below 1. bicycle-$20 2. unicycle $10 3. tire-$5 4. pump-$2 5. chain-$1 As products are sold throughout the day, each salesperson enters in their sales number followed by the number of the product they sold. For example, if salesperson 3 sold a pump, he/she would enter in "3 4". You need to write a program that will continue allowing the users to enter in sales in the given format until"-1 -1" is entered as a value. At this point, the program should print out the total amount of money that the company owes each of the sales people.

Explanation / Answer

#include <stdio.h>

int main() {

int s_man[6]={0};

//above array will be storing the commission for various sales person,

int id,item;

// variable id corresponds to saleman number and item corresponds to item number.

scanf("%d %d",&id,&item);

//this line will get the values for the varibles id and item.

while(id!=-1 && item!=-1)

{

int comm = 0;

switch(item)

// we are using a switch case to find out the commission for the item though you can use if-else ladder too.

{

case 1: comm=20;

break;

case 2: comm=10;

break;

case 3: comm=5;

break;

case 4: comm=2;

break;

case 5: comm=1;

break;

default: printf("Invaid Choice");

}

s_man[id]+=comm;

//this line will keep on updating the values for the commission earned by person.

scanf("%d %d",&id,&item);

//this line will get the values for the varibles id and item.

}

for (int i=1;i<=5;i++)

{

printf("Pay of salesman %d is %d ",i,s_man[i]);

// this loop will simply print the content of array, which is the comissions earned by a salesman.

}

return 0;

}