I am back this week with another homework problem. My array is not working like I thought it would. My brain is about to explode trying to comprehend what is going on. This code will compile but, it won't do what I want it to. The array is supposed to have columns of employee numbers and rows of product numbers. Then you can input an employee number and product number and add to that total for a given number of days. For some reason my for statement for the number of days is not working. And the employee number and product numbers are not going where I think they should be. The total code at the bottom is a little sloppy and I can fix that once I can get the array problem figured out. Any help would be greatly appreciated.
Here is the code.
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
int main ()
{
int days = 0;
int productTotal = 0;
int sales[5][5] = {{0},{0}};
int employeeNumber = 1;
cout << "Enter number of days and program will request input for each day: ";
cin >> days;
cout << endl;
for ( int x=0; x < days; x++)
{
while (employeeNumber > 0)
{
int productNumber = 1;
cout << "Enter employee number(1-5) for day " << x << "(to move to next day enter 0): ";
cin >> employeeNumber;
cout << endl;
switch (employeeNumber)
{
case 0:
break;
case 1:
cout << "Enter product number(1-5) (enter 0 to exit): ";
cin >> productNumber;
if (productNumber = 0)
break;
else
{
cout << endl;
cout << "Enter product total as a positive whole number: ";
cin >> productTotal;
cout << endl;
sales[0][productNumber-1] += productTotal;
cout << endl;
}
break;
case 2:
while (productNumber > 0)
{
cout << "Enter product number(1-5) (enter 0 to exit): ";
cin >> productNumber;
if (productNumber = 0)
break;
else
{
cout << endl;
cout << "Enter product total as a positive whole number: ";
cin >> productTotal;
cout << endl;
sales[1][productNumber-1] += productTotal;
cout << endl;
}
}
break;
case 3:
while (productNumber > 0)
{
cout << "Enter product number(1-5) (enter 0 to exit): ";
cin >> productNumber;
if (productNumber = 0)
break;
else
{
cout << endl;
cout << "Enter product total as a positive whole number: ";
cin >> productTotal;
cout << endl;
sales[2][productNumber-1] += productTotal;
cout << endl;
}
}
break;
case 4:
while (productNumber > 0)
{
cout << "Enter product number(1-5) (enter 0 to exit): ";
cin >> productNumber;
if (productNumber = 0)
break;
else
{
cout << endl;
cout << "Enter product total as a positive whole number: ";
cin >> productTotal;
cout << endl;
sales[3][productNumber-1] += productTotal;
cout << endl;
}
}
break;
case 5:
while (productNumber > 0)
{
cout << "Enter product number(1-5) (enter 0 to exit): ";
cin >> productNumber;
if (productNumber = 0)
break;
else
{
cout << endl;
cout << "Enter product total as a positive whole number: ";
cin >> productTotal;
cout << endl;
sales[4][productNumber-1] += productTotal;
cout << endl;
}
}
break;
}
}
}
cout << "The sales totals per employee per product number are as follows: " << endl;
cout << "Employee#: 1 2 3 4 5" << endl;
int i = 0;
int j = 0;
for ( i = 0; i < 5; i++ )
{
cout << "Product #: " << i+1 << " ";
for (j = 0; j < 5; j++ )
{
cout << sales[i][j] << " ";
}
cout << endl;
}
for ( i = 0; i < 5; i++ )
{
int total = 0;
for ( j = 0; j < 5; j++ )
{
total += sales[i][j];
}
cout << "Employee #" << i+1 << " month total: " << total << " ";
cout << endl;
}
for ( j = 0; j < 5; i++ )
{
int total = 0;
for (i = 0; j < 5; j++ )
{
total += sales[j][i];
}
cout << "Product #" << j+1 << " month total: " << total << " ";
cout << endl;
}
}