how do i write a C program that accepts sales made by 5 sales reps for the 4 months that they have been selling the company's products. The program should then find the total sales for 4 months, total sales for each sales rep, and total sales per month. The highest and lowest sales for each sales rep and for each month?

anja

To write a C program that accomplishes the tasks you described, you can follow these steps:

1. Define the necessary variables: You need variables to store the sales data, such as salesRepSales[5][4] to hold the sales made by each sales representative for each month, as well as other variables to calculate totals and find the highest and lowest sales values.

2. Accept input from the user: Use loops and scanf statements to obtain the sales data from the user. Loop through each sales representative and month to gather the sales values.

3. Calculate the total sales: Use nested loops to iterate through the sales data array and accumulate the sales values to calculate the total sales for the 4 months.

4. Calculate the total sales for each sales representative: Use a loop to iterate through each sales rep's sales and sum them up separately.

5. Calculate the total sales per month: Use another loop to iterate through each month's sales and sum them up separately.

6. Find the highest and lowest sales for each sales representative and month: Use loops to loop through each sales rep and month, keeping track of the highest and lowest sales values encountered.

7. Display the results: Print out the total sales for 4 months, total sales for each sales rep, total sales per month, and the highest and lowest sales values for each sales rep and month.

Here's a code example to illustrate the steps described above:

```c
#include<stdio.h>

int main() {
int salesRepSales[5][4];
int totalSales = 0;

// Accept input from the user
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
printf("Enter sales made by sales rep %d for month %d: ", i + 1, j + 1);
scanf("%d", &salesRepSales[i][j]);

// Calculate the total sales
totalSales += salesRepSales[i][j];
}
}

int totalSalesPerRep[5] = {0}; // Stores total sales for each sales rep
int totalSalesPerMonth[4] = {0}; // Stores total sales for each month

// Calculate total sales for each sales representative
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
totalSalesPerRep[i] += salesRepSales[i][j];
}
}

// Calculate total sales per month
for (int j = 0; j < 4; j++) {
for (int i = 0; i < 5; i++) {
totalSalesPerMonth[j] += salesRepSales[i][j];
}
}

// Find highest and lowest sales per sales representative and month
int highestSalesPerRep[5] = {0};
int lowestSalesPerRep[5] = {INT_MAX};
int highestSalesPerMonth[4] = {0};
int lowestSalesPerMonth[4] = {INT_MAX};

for (int i = 0; i < 5; i++) {
for (int j = 0; j < 4; j++) {
if (salesRepSales[i][j] > highestSalesPerRep[i]) {
highestSalesPerRep[i] = salesRepSales[i][j];
}

if (salesRepSales[i][j] < lowestSalesPerRep[i]) {
lowestSalesPerRep[i] = salesRepSales[i][j];
}

if (salesRepSales[i][j] > highestSalesPerMonth[j]) {
highestSalesPerMonth[j] = salesRepSales[i][j];
}

if (salesRepSales[i][j] < lowestSalesPerMonth[j]) {
lowestSalesPerMonth[j] = salesRepSales[i][j];
}
}
}

// Display the results
printf("\nTotal sales for 4 months: %d\n", totalSales);

for (int i = 0; i < 5; i++) {
printf("Total sales for sales rep %d: %d\n", i + 1, totalSalesPerRep[i]);
printf("Highest sales for sales rep %d: %d\n", i + 1, highestSalesPerRep[i]);
printf("Lowest sales for sales rep %d: %d\n", i + 1, lowestSalesPerRep[i]);
}

for (int j = 0; j < 4; j++) {
printf("Total sales for month %d: %d\n", j + 1, totalSalesPerMonth[j]);
printf("Highest sales for month %d: %d\n", j + 1, highestSalesPerMonth[j]);
printf("Lowest sales for month %d: %d\n", j + 1, lowestSalesPerMonth[j]);
}

return 0;
}
```

That's it! Now you have a C program that accepts sales data from 5 sales representatives over 4 months, and calculates various statistics like total sales, total sales per sales rep, total sales per month, and the highest and lowest sales values for each sales rep and month.