Need assistance with c++ program

This program is supposed to use a double scripted array-A company has 4 salespeople(numbered 1-4)who each sell five different products(numbered 1-5)Once a day, each salesperson passes in a slip for each separate product sold. In the slip, the information is as follows: a. The salesperson number
b. The product number.
c. The total dollar value of the product sold that day
My code didnt do what i wanted, so i decided to take a fresh start, but its worse than before now:(
Post both sets of code you have so we can help you with the exact problem. If you just post a question there is no way for us to help unless you expect someone to do the assignment for you.
here is my code-it doesnt really work

#include<iostream>
using namespace std;
main()
{

int sales[4][6]={0};

int salesPerson, product,value, totalSales=0,i,j,k,m,totalProduct=0;

/*Enter Data*/

cout<<("Enter the salesperson, product, and total sales.\nEnter -1 for the salesperson to end input.");
cin >>salesPerson;

while(salesPerson!=-1)
{

cin >>product;
cin >>value;
sales[salesPerson][product]=value;
cin >>salesPerson;

}

//print Column Header(Product Numbers)
cout<<" ";
for (i = 1; i <= 5; i++)
{
cout/*<<"%5d"*/c<<i;
}
cout<<"\n\n";
//print Salesman no and item values
for (i = 0; i < 4; i++)
{
cout<<i;
for (j = 0; j < 5; j++)
{
cout/*<<"%5d"*/<<sales[i][j];
}
//find and print sum of the products sold per Salesman
for (k = 0; k < 5; k++)
{
totalSales+=sales[i][k];
}

cout<</*" %5d\n"<<*/totalSales;
totalSales=0;
}
//find and print total number of specific product sold
cout<<"\n ";
for (i = 0; i < 5; i++)
{
for (m = 0; m< 4; m++)
{
totalProduct+=sales[m][i];
}
cout<</*"%5d"<<*/totalProduct;
totalProduct=0;
}
}



your while loop has no way to exit. It will continuously loop.

Also not sure what these lines of code mean: cout/*<<"%5d"*/c<<i;

In your for loop you can use the "i" for(int i = 0; i < someSize; i++) in all your for loops because it is only defined in the scope of the for loop.
oh my intention was to truncate it but it didnt work so i commented it out.
i tried a fresh start, but a couple statements i cannot figure out. Could you help?
//defining libraries to be used
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
const int PEOPLE = 5;
const int PRODUCTS = 6;
int sales[6][7];
double value;
double totalSales;
double productSales[ PRODUCTS ] = { 0.0 };
int salesPerson;
int product;

// enter sales slips
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;
/* Could you write a statement that adds values to the proper element in the sales array */
cin >> salesPerson;
} // end while

cout << "\nThe 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.\n " << setw( 12 )
<< 1 << setw( 12 ) << 2 << setw( 12 ) << 3 << setw( 12 ) << 4
<< setw( 12 ) << 5 << setw( 13 ) << "Total\n" << fixed << showpoint;

// display salespeople and sales
for ( int i = 1; /* Im not sure what condition goes here */; i++ )
{
totalSales = 0.0;
cout << i;

// add total sales, and display individual sales
for ( int j = 1; /* Im not sure what condition goes here */; j++ )
{
/*Which statement would add the current sales element to totalSales */
cout << setw( 12 ) << setprecision( 2 ) << sales[ i ][ j ];
/* Which statement would add the current sales element to productSales */
} // end inner for

cout << setw( 12 ) << setprecision( 2 ) << totalSales << '\n';
} // end outer for

cout << "\nTotal" << setw( 8 ) << setprecision( 2 ) << productSales[ 1 ];

// display total product sales
for ( int j = 2; j < PRODUCTS; j++ )
cout << setw( 12 ) << setprecision( 2 ) << productSales[ j ];

cout << endl;
} // end main
It would have token me too long to fill all the data from the console at each execution, so I created a file from which they could be easily read.
This is the file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1 1 11
1 2 12
1 3 13
1 4 14
1 5 15
2 1 21
2 2 22
2 3 23
2 4 24
2 5 25
3 1 31
3 2 32
3 3 33
3 4 34
3 5 35
4 1 41
4 2 42
4 3 43
4 4 44
4 5 45


The read-input-from-console routine it’s still there, anyway, but commented out.

Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// This program is supposed to use a double scripted array
// A company has 4 salespeople (numbered 1-4) who each sell
// five different products(numbered 1-5).
// Once a day, each salesperson passes in a slip for each separate product sold.
// In the slip, the information is as follows:
//    a. The salesperson number
//    b. The product number.
//    c. The total dollar value of the product sold that day
#include<fstream>
#include<iostream>
#include<iomanip>

int main()
{
    const int SALESPERSONS = 4;
    const int PRODUCTS = 5;
    double sales[SALESPERSONS+1][PRODUCTS+1] {0.0};

    /* RESTORE THIS PART FOR INPUT FROM THE USER
    // enter sales slips
    std:: cout << "Please, enter the salesperson (1 - 4), "
                  "product number (1 - 5), "
                  "and total sales."
                  "\nEnter -1 for the salesperson to end input.\n";

    int sales_person {0};
    std::cin >> sales_person;

    // continue receiving input for each salesperson until -1 is entered
    int product {0};
    double value {0.0};
    while ( sales_person != -1 )
    {
        std::cin >> product >> value;
        sales[sales_person-1][product-1] += value;
        sales[sales_person-1][PRODUCTS] += value;
        sales[SALESPERSONS][product-1] += value;
        std::cin >> sales_person;
    } // end while
    */

    // READING INPUT FROM FILE
    std::ifstream idata("its20alif.txt");
    int i {0}, j {0};
    double value {0.0};
    while(idata >> i >> j >> value) {
        sales[i-1][j-1] += value;
        sales[i-1][PRODUCTS] += value;
        sales[SALESPERSONS][j-1] += value;
    }

    std::cout << "\nThe total sales for each salesperson are displayed at the "
                 "end of each row,\nand the total sales for each product "
                 "are displayed at the bottom of each column.\n "
              << std::setw(12) << 1 << std::setw(12) << 2 << std::setw(12) << 3
              << std::setw(12) << 4 << std::setw(12) << 5 << std::setw(13)
              << "Total\n" << std::fixed << std::showpoint;

    // display salespeople and sales
    for ( int i = 0; i<=SALESPERSONS; i++ )
    {
        std::cout << (i+1);

        for ( int j = 0; j<=PRODUCTS; j++ )
        {
            std::cout << std::setw(12) << std::setprecision(2) << sales[i][j];
        }
        std::cout << std::endl;
    }
    std::cout << std::endl;

    return 0;
}


Output:

The total sales for each salesperson are displayed at the end of each row,
and the total sales for each product are displayed at the bottom of each column.
            1           2           3           4           5       Total
1       11.00       12.00       13.00       14.00       15.00       65.00
2       21.00       22.00       23.00       24.00       25.00      115.00
3       31.00       32.00       33.00       34.00       35.00      165.00
4       41.00       42.00       43.00       44.00       45.00      215.00
5      104.00      108.00      112.00      116.00      120.00        0.00

Sure, I can try to help but what exactly do you need help with? It appears you got your desired output.
Topic archived. No new replies allowed.