I have gotten my program to the point that it allows me to enter the data I want to enter. However, I do not know how to get the program to loop back correctly and ask for salesperson number and stop the loop when I enter -1.
Help!
#include <stdio.h>
int main()
{
const int PEOPLE = 5, PRODUCTS = 6;
double sales[ 5 ][ 6 ] = { 0.0 }, value;
double totalSales, productSales[ 6 ] = { 0.0 };
int salesPerson, product;
int i, j;
salesPerson = 0;
product =0;
value = 0;
printf("Enter the sales person (1 - 4) Enter -1 to end input:");
scanf("%d", &salesPerson);
while ( salesPerson != -1 ) {
printf("Enter product number (1 - 5):\n");
scanf("%d" ,&product) ;
printf("Enter total sales of product:\n");
scanf("%d", &value);
sales[ salesPerson ][ product ] += value;
}
printf("\nThe total sales for each sales person ");
printf("are displayed\nat the end of each row,");
printf("and the total sales for each\nproduct ");
printf("are displayed at the bottom of each column.\n");
printf("%10d", 1);
printf("%10d", 2);
printf("%10d", 3);
printf("%10d", 4);
printf("%10d", 5);
printf("%12d", "Total\n");
for ( i = 1; i < PEOPLE; ++i ) {
totalSales = 0.0;
printf("%d", i);
for ( j = 1; j < PRODUCTS; ++j ) {
totalSales += sales[ i ][ j ];
printf("%.2f", sales [i][j]);
productSales[ j ] += sales[ i ][ j ];
}
printf("%.2f", sales[i][j]);
}
printf( "%.2f,","\nTotal",productSales );
for ( j = 2; j < PRODUCTS; ++j ) {
printf("%.2f", productSales[j]);
}
return 0;
}