#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;
}
mvmalderen commented: Java program in C++ ? -4

Recommended Answers

All 4 Replies

We would but apparently what effort did you put into doing that ? Heck it seems you dint even put the effort to read this announcement nor this which are highlighted at the top of the Java Forum, So why should we help you ???

Is this even C++ ?

What is this:
<strong class="highlight">for</strong>

It seems to me that you copy-pasted from the source code of a web page and by posting it like this, we get the impression that you don't even know C++ or you didn't bother to post it in a readable way for the rest of us.

Do not even look at this code , just write java code to calculate total sale price from user inputs .

Do not even look at this code , just write java code to calculate total sale price from user inputs .

I get it now.
I was sent a PM from chingkoysilog (the OP) asking to give him the solution of an assignment that involved salespersons and calculating some total values per products and salespersons.

He probably found the solution from the internet in C++ and now wants someone to convert it in java.

If chingkoysilog disagrees then please correct me, by posting your code and explaining what is your problem so we can help you.

commented: ok. +12
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.