Hello, I am attempting to write a program in c. First I will put in my program so far. If you are willing to help I would appreciate it. It compiles ok but does not work correctly.
Here is what I am trying to accomplish:
Use a double-subscripted array to solve the following problem. A company has four salespeople (1 to 4) who sell five different products (1 to 5). Once a day, each salesperson passes in a slip for each different type of product sold. Each slip contains:
* The salesperson number
* The product number
* 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 is available. Write a program that will read all this information for last month’s sales and summarize the total sales by salesperson by product. All totals should be stored in the double-subscripted 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, and 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.
Hints:
For each of 4 salespeople, you need to read in the sales for each of 5 products for each of 20 days.
As you are developing your program, you may want to test for smaller numbers of salespeople, products, and/or days, to avoid inputting large numbers of values each time. When you get the program working for smaller numbers, increase to the required values.
Code:
#include <stdio.h>
int main()
{
int i= 0;
int j= 0;
const int People = 5;
const int Products = 6;
int sales[3][4] = {0};
int totalSales;
int productSales[4] = {0};
int setw[5]= {0};
int salesPerson=0;
int product= 1;
printf("Enter the salesPerson number (1-4). Enter salesPerson number -1 to end input:");
scanf_s ("%d", salesPerson);
while (salesPerson != -1)
{
printf("Enter the salesPerson number 1-4). Enter salesPerson number-1 to end input:");
if (salesPerson= -1&&salesPerson>0&&salesPerson<6)
{
printf("ProductNumber:\n");
scanf_s("%d", product);
printf("Number of Product Units Sold:\n");
printf("%d", sales[product-1][salesPerson-1]);
}
}
printf("The total sales for each salesPerson are displayed at the\n");
printf("bottom of each column,and the total sales for each product\n");
printf("are displayed at the end of each row.\n ");
setw[5];
{
printf("Total\n");
}
for (i =0;i<= 5;i++)
{
totalSales = 0;
printf("%d", i);
for (j=0;j<= 4;j++)
{
totalSales+=sales[i][j];
printf( "%d", sales[i][j]);
}
printf("totalSales=\n");
}
/*display total product sales*/
for (i =0;i< 5;i++)
{
totalSales = 0;
for (j=0;j<6;j++)
{
totalSales+=sales[j][i];
}
if(i==0)
{
printf("Total\n",totalSales);
}
else
printf("\n",totalSales);
}
return 0;
}