#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, <strong class="highlight">PRODUCTS</strong> = 6;
double sales[ PEOPLE ][ <strong class="highlight">PRODUCTS</strong> ] = { 0.0 }, value,
totalSales, productSales[ <strong class="highlight">PRODUCTS</strong> ] = { 0.0 };
int <strong class="highlight">salesPerson</strong>, <strong class="highlight">product</strong>;
cout << "Enter <strong class="highlight"><vb_highlight>the</strong></vb_highlight> sales person <strong class="highlight"><vb_highlight>(1</strong></vb_highlight> - <strong class="highlight">4)</strong>, "
<< "product number <strong class="highlight"><vb_highlight>(1</strong></vb_highlight> - 5)\nand total sales."
<< "Enter -1 <strong class="highlight">for</strong> <strong class="highlight"><vb_highlight>the</strong></vb_highlight> sales person <strong class="highlight"><vb_highlight><vb_highlight>to</strong></vb_highlight></vb_highlight> end input.\n";
cin >> <strong class="highlight">salesPerson</strong>;
while ( <strong class="highlight">salesPerson</strong> != -1 ) {
cin >> <strong class="highlight">product</strong> >> value;
sales[ <strong class="highlight">salesPerson</strong> ][ <strong class="highlight">product</strong> ] += value;
cin >> <strong class="highlight">salesPerson</strong>;
}
cout << "\nThe total sales <strong class="highlight">for</strong> <strong class="highlight"><vb_highlight><vb_highlight>each</strong></vb_highlight></vb_highlight> sales person "
<< "are displayed\nat <strong class="highlight"><vb_highlight>the</strong></vb_highlight> end <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight><vb_highlight>each</strong></vb_highlight></vb_highlight> row,"
<< "and <strong class="highlight"><vb_highlight>the</strong></vb_highlight> total sales <strong class="highlight">for</strong> each\nproduct "
<< "are displayed at <strong class="highlight"><vb_highlight>the</strong></vb_highlight> bottom <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight><vb_highlight>each</strong></vb_highlight></vb_highlight> 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 );
<strong class="highlight">for</strong> ( int i = 1; i < PEOPLE; ++i ) {
totalSales = 0.0;
cout << i;
<strong class="highlight">for</strong> ( int j = 1; j < <strong class="highlight">PRODUCTS</strong>; ++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 ];
<strong class="highlight">for</strong> ( int j = 2; j < <strong class="highlight">PRODUCTS</strong>; ++j )
cout << setw( 10 ) << setprecision( 2 )
<< productSales[ j ];
cout << endl;
return 0;
}
stephen84s 550 Nearly a Posting Virtuoso Featured Poster
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
ithelp 757 Posting Virtuoso Banned
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
ithelp commented: ok. +12
iamthwee commented: yeah he got the code from daniweb +22
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.