I am trying to get my 2d array to total up values. It is laid out perfectly, but my values do not calculate. Is my math wrong?
Please help??
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <iomanip>
using std::setw;
int main()
{
const int DAY = 7;
const int PRODUCTS = 5;
double purchased[ DAY ][ PRODUCTS ] = { 0 };
double quantity;
double totalQ;
double productQ[ PRODUCTS ] = { 0 };
int dayNum;
int product=0;
cout << "Enter the Day Number (1 - 6), \n"
<< "\nProduct Number (1 - 4), \n\nQuantity Purchased,\n"
<< "\nEnter -1 for the Day Number to end input.\n";
cin >> dayNum;
while ( dayNum != -1 )
{
cin >> dayNum >> quantity;
purchased[ dayNum ][ product ] += quantity;
cin >> dayNum;
}
cout << setw(30) << "Products\n" << setw(0)
<< "Day #" << setw( 6 ) << 1 << setw( 10 ) << 2
<< setw( 10 ) << 3 << setw( 10 ) << 4
<< setw( 13 ) << "Total\n\n";
for ( int i = 1; i < DAY; ++i )
{
totalQ = 0;
cout << i;
for ( int j = 1; j < PRODUCTS; ++j ) {
totalQ += purchased[ i ][ j ];
cout << setw( 10 ) << purchased[ i ][ j ];
productQ[ j ] += purchased[ i ][ j ];
}
cout << setw( 10 ) << totalQ << '\n';
}
cout << "\nTotal" << setw( 6 ) << productQ[ 1 ];
for ( int j = 2; j < PRODUCTS; ++j )
cout << setw( 10 ) << productQ[ j ];
cout << endl;
return 0;
}