Use a doublesubscripted array and functions to solve the fol

Use a double-subscripted array and functions to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Each salesperson passes in slips for each different type of product sold. Each slip contains the following: a) The salesperson number b) The product number c) The total dollar value of that product sold that day Thus, each salesperson passes in between 0 and 5 sales slips per day. Assume that the information from all of the slips for last month are available. Write a program that reads all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the two-dimensional array sales. After processing all the information for last month, print the results in tabular format with each of the columns representing a particular salesperson and each of the rows representing a particular product. Cross total each row to get the total sales of each product for last month; cross total each column to get the total sales by salesperson for last month. Your tabular printout should include these cross totals to the right of the totaled rows and to the bottom of the totaled columns. A template has been provided. S A M P L E I N P U T Enter the salesperson (1 - 4), product number (1 - 5) and total sales. Enter -1 for the salesperson to end input. 1 1 9.99 3 3 5.99 2 2 4.99 -1 S A M P L E O U T P U T The total sales for each sales person are displayed at the end of each row, and the total sales for each product are displayed at the bottom of each column. 1 2 3 4 5 Total 1 9.99 0.00 0.00 0.00 0.00 9.99 2 0.00 4.99 0.00 0.00 0.00 4.99 3 0.00 0.00 5.99 0.00 0.00 5.99 4 0.00 0.00 0.00 0.00 0.00 0.00 Total 9.99 4.99 5.99 0.00 0.00

Solution

The code for the above scenario is as follows:

#include <stdio.h>

int main(void)

{

int sales[4][6]={0};

int salesPerson, product,value, totalSales=0,i,j,k,m,totalProduct=0;

printf(\"Enter the salesperson, product, and total sales.\ Enter -1 for the salesperson to end input.\");

scanf(\"%d\",&salesPerson);

while(salesPerson!=-1){

scanf(\"%d %d\", &product, &value);

sales[salesPerson][product]=value;

scanf(\"%d\", &salesPerson);

}

printf(\" \");

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

{

printf(\"%5d\",i);

}

printf(\"\ \ \");

// To print the Salesman number and the item number values

for (i = 0; i < 4; i++)

{

printf(\"%d\",i);

for (j = 0; j < 5; j++)

{

printf(\"%5d\", sales[i][j]);

}

// To find the sum of the products sold per Salesman and print them.

for (k = 0; k < 5; k++)

{

totalSales+=sales[i][k];

}

printf(\" %5d\ \", totalSales);

totalSales=0;

}

//To find the total number of specific product sold and print them

printf(\"\ \");

for (i = 0; i < 5; i++)

{

or (m = 0; m< 4; m++)

{

totalProduct+=sales[m][i];

}

printf(\"%5d\",totalProduct);

totalProduct=0;

}

getch();

return 0;

}

Use a double-subscripted array and functions to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5).
Use a double-subscripted array and functions to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5).

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site