Friday, March 16, 2012

Total Sales

A company has four salespeople who sells five different products.Once a day, each salespeople passes in a slip for each different type of product sold.Each slip contains:
  • The salespeople number
  • The product number
  • The total dollar value of that product sold that day
The program below will read all the information for last month's sales and summarize the total sales by salespeople by product and then print the result in a tabular format.
/*
   title: totalSales
   coder:aeriqusyairi
   date: Jan29 2012
*/
#include<stdio.h>
#define PRODUCT 5
#define SALESPERSON 4
int main(){
   int sales[ PRODUCT ][ SALESPERSON ] = { 0 };
   int totalByProduct[ PRODUCT ] = { 0 };
   int totalByPerson[ SALESPERSON ] = { 0 };
   int options = 1, i, j, personNumber, productNumber, totalSold;
   
   while( options == 1 ){
      printf("*******\nOptions\n*******\n"
             "1.Pass sales slip\n"
             "2.Compute and tabulate overall data\n"
             "Options:");
      scanf("%d", &options);
      
      if( options == 1 ){
         printf("Salesperson number:");
         scanf("%d", &personNumber );
         printf("Product number:");
         scanf("%d", &productNumber );
         printf("Total sold today:" );
         scanf("%d", &totalSold );
         
         sales[ productNumber - 1 ][ personNumber - 1 ] += totalSold;         
      }
   }  
   
   if( options == 2 ){
      printf("\n\n************\nData summary\n************"
             "\n\n  %5d%5d%5d%5d\n\n", 1, 2, 3, 4 );
      for( i = 0; i < PRODUCT; i++ ){
         printf("%2d", i + 1 );  
         for( j = 0; j < SALESPERSON; j++ ){
            printf("%5d", sales[ i ][ j ] ); 
            totalByProduct[ i ] += sales[ i ][ j ];    
         }    
         
         printf("%5d\n", totalByProduct[ i ] );
      }
      
      printf("\n  ");
      
      for( i = 0; i < SALESPERSON; i++){
         for( j = 0; j < PRODUCT; j++ ){
            totalByPerson[ i ] += sales[ j ][ i ];     
         }
         
         printf("%5d", totalByPerson[ i ] );
      }
      
      printf("\n\n");
   }
   
   system("pause");
   return 0; 
}

No comments:

Post a Comment