GooeyG 0 Light Poster

A company has four sales people (1 to 4) who sell five different products(1 to 5). Once a day, each salesperson passes a slip for each different type of product sold. Each slip contains the following:

a)the salesperson number
b)product number
c)total dollar value of that product sold that day

Write a program that will read all the information and summarize the total sales by salesperson by product. All totals should be stored int he 2D array sales.

I'm struggling with inputing data into the 2D array. There is another post with the same question on here, which i didn't really understand what he did(http://www.daniweb.com/forums/thread119484.html). I'll post it too. Of course, i can take the easy road and copy it and call it good, but that doesn't do me any good.

I haven't completed the whole program. I'm just trying to get the beginning functionality understood,working, and take it from there. Thanks.

#include<iostream>
using std::cout;
using std::cin;
using std::endl;
using std::ios;

#include <iomanip>
 
using std::setiosflags;
using std::setprecision;
using std::setw;

int main()
{
	const int PRODUCT = 6;
	const int PEOPLE = 6;
	int sales[PEOPLE][PRODUCT] = {0};
	double productSales[PRODUCT] = { 0.0 }, totalDollar[PRODUCT] = { 0.0}, totalSales ;

	//int salesPeople[SIZE] = {0}; 
	//int salesP1,salesP2,salesP3,salesP4;
	int salesId, productNum, count, totalSalesArray;
	
	//double totalProductSold,  

	cout << "How many sales people do you want to enter?\n";
	cin >> count; 

	int i = 0;
	
	cout << "Please enter your sales person's id(press -1 to exit): \n";
	cout << "Please enter product number:\n";

	for(int i = 0; i < count; i++)
	{
		for(int a = 0; a < count; a++)
		{
			cin >> sales[i][a];
		}
	}

	//display output
	for(int i = 0; i < count; i++)
	{
		for(int a = 0; i < count; a++)
		{
			cout << sales[i][a] << endl;;
		}
	}
return 0;

}

Here is the other guy's code:

#include <iostream>
 
using std::cout;
using std::cin;
using std::endl;
using std::ios;
 
#include <iomanip>
 
using std::setiosflags;
using std::setprecision;
using std::setw;
 
int main()
{
   const int PEOPLE = 5, PRODUCTS = 6;
   double sales[ PEOPLE ][ PRODUCTS ] = { 0.0 }, value,
         totalSales, productSales[ PRODUCTS ] = { 0.0 };
   int salesPerson, product;
 
   cout << "Enter the sales person (1 - 4), "
        << "product number (1 - 5)\nand total sales."
        << "Enter -1 for the sales person to end input.\n";
   cin >> salesPerson;
 
   while ( salesPerson != -1 )
   {
      cin >> product >> value;   //this is where i get lost, i thought working with 2d array, you have to use a nested for loop.  
      sales[ salesPerson ][ product ] += value;  //can someone explain this one too?
      cin >> salesPerson;
   }
 
   cout << "\nThe total sales for each sales person "
        << "are displayed\nat the end of each row,"
        << "and the total sales for each\nproduct "
        << "are displayed at the bottom of each column.\n"
        << setw( 10 ) << 1 << setw( 10 ) << 2
        << setw( 10 ) << 3 << setw( 10 ) << 4
        << setw( 10 ) << 5 << setw( 12 ) << "Total\n"
        << setiosflags( ios::fixed | ios::showpoint );
 
   for ( int i = 1; i < PEOPLE; ++i ) 
   {
      totalSales = 0.0;
      cout << i;
 
      for ( int j = 1; j < PRODUCTS; ++j ) 
	  {
         totalSales += sales[ i ][ j ];
         cout << setw( 10 ) << setprecision( 2 )
              << sales[ i ][ j ];
         productSales[ j ] += sales[ i ][ j ];
      }
 
      cout << setw( 10 ) << setprecision( 2 )
           << totalSales << '\n';
   }
 
   cout << "\nTotal" << setw( 6 ) << setprecision( 2 )
        << productSales[ 1 ];
 
   for ( int j = 2; j < PRODUCTS; ++j )
      cout << setw( 10 ) << setprecision( 2 )
           << productSales[ j ];
 
   cout << endl;
   return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.