I am trying to solve a problem from a lab challenge. I'm having trouble on how to output the table and it must be done in top-down design.

Use a two-dimensional 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 following:
a) The salesperson number
b) The product number
c) 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 two-dimensional 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; 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

My coding:

#include "stdafx.h"
#include <iostream>
using namespace std;

const int PEOPLE = 5, PRODUCTS = 6;

void fill ( double sales [][PRODUCTS] )
{
	int salesperson, product;
	double value;

   cout << "Enter the salesperson (1 - 4), product number (1 - 5), and "
        << "total sales.\nEnter -1 for the salesperson to end input.\n";
   cin >> salesperson;
   
   // continue receiving input for each salesperson until -1 is entered
   while ( salesperson != -1 ) 
   {
      cin >> product >> value;
	  
	  sales[salesperson][product] += value;
   
      cin >> salesperson;

   }
}//end fill

void rows ( double sales[][PRODUCTS] )
{
	int k, m;

	for (k = 0; k < 1; k++ )
	{ for (m = 0; m < 2; m++ )
		sales[k][PRODUCTS] = sales[k][0] + sales[k][m];

	}//end for
}//end rows

void columns ( double sales[][PRODUCTS])
{
	int k, m;

	for (k = 0; k < 1; k++ )
	{ for (m = 0; m < 2; m++ )
		sales[PEOPLE][k] = sales[0][k] + sales[m][k];



	}//endfor
}//end columns


void print ( double sales[][PRODUCTS])
{
	

	
}//end print
int main ()
{
	double sales[PEOPLE][PRODUCTS] = {0.0};
	
fill(sales);
rows(sales);
columns(sales);
print(sales);
}

I'm not sure what to put in the print module to print out the table. Any help would be appreciated.

just print out the array using 2 for loops.

something like

int a[m][n];
cout << "Name" << " " << "Total" << endl;
for(int i=0;i<m;i++)
{
     for(int j=0;j<n;j++)
     {
          cout << a[i][j] << " " ;
     }
   cout << endl;
}

do some formatting.

commented: Say "Yes" to formatting +15
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.