i want to output the array in tabular form but when i run the code i get a strange number -858993460 repeating itself many times. Any suggestions ? My code is below.
Put the code you need help with here.
#include <iostream>
usingnamespace std;
void main()
{
int Sales_Prsn = 0, Prod_Num = 0;
double T_Sales = 0;
int a[11][6];
cout << "Enter the salesperson number, product number, and total sales.\n"
<< "(Enter -1 for the salesperson to end input):";
cin >> Sales_Prsn >> Prod_Num >> T_Sales;
cout << endl;
while (Sales_Prsn != -1)
{
cout << "Enter the salesperson number, product number, and total sales.\n"
<< "(Enter -1 for the salesperson to end input):";
cin >> Sales_Prsn >> Prod_Num >> T_Sales;
cout << endl;
a[Sales_Prsn][Prod_Num] = T_Sales;
}
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 6; j++)
cout << a[i][j] << endl;
}
}
Lines 11-14: Why are these lines here? You're just going to overlay the values initially entered with the values entered at line 20.
Line 22: You're assuming the salesmen are numbered from 0 to 10 and the products are numbered from 0 to 5. Any other values are going to cause you to make an out of bounds reference to your array.
Lines 24-27: Your print loop assumes exactly 11 salespeople were entered and that each salesperson sold exactly 6 items. Your while loop at line 16 does not guarantee this.