Skip to content

Instantly share code, notes, and snippets.

Created October 26, 2013 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/7173864 to your computer and use it in GitHub Desktop.
Save anonymous/7173864 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
using namespace std;
const int people = 4;
const int products = 5;
void print_array(int[][products]);
int sales[people][products];
int main()
{
int salesperson; //declare salesperson variable to use in while loop
int product; // variable for user to input product number
int amountSold; // variable for user to input quantity sold.
cout << "Enter the salesperson (1-4), product number (1-5), and total sales" << endl;
cout << "Enter -1 for the salesperson to end input. " << endl;
while (1==1)
{
cin >> salesperson;
if (salesperson == -1)
{
break;
}
else
{
cin >> product >> amountSold;
sales[salesperson - 1][product - 1] += amountSold;
}
}
cout << "The total sales for each salesperson are displayed at the end of each row\n" <<
"and the total sales for each product are displayed at the bottom of each column" << endl;
cout << "\n" << setw(7) << "1" << setw(7) << "2" << setw(7) << "3" << setw(7) << "4" << setw(7) << "5" << setw(10) << "Total" << endl;
print_array(sales);
}
void print_array(int sales[][products])
{
int total;
for (int i = 0; i < people; i++)
{
total = 0;
cout << "\n";
for (int j = 0; j < products; j++)
{
cout << setw(7);
cout << sales[i][j];
total += sales[i][j];
}
cout << setw(7) << total;
cout << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment