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.
//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;
}
}
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
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:
// 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()
{
constint SALESPERSONS = 4;
constint 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