OK - I'm stumped I'm filling a 2D arraywith inputs, then when it hits the first function - for some reason the very first value in the array is being changed to -5

If I comment the function out, it's fine - it gets passes and passed back with no trouble - what further excerbates my confusiont is that it's being sent as a constant and still getting changed somehwhere

using namespace std;

#include <iostream>
#include <iomanip>
#include <cmath>

// ------ Prototypes ---------------------------------------------
void getDivSales(double[][4]);
void divQIncDec(const double [][4], double [][3]);
void totSalesQrtr(const double[][4], double[4]);
void averageDivSales(const double[][4], double[6]);
void highestDivisionQrtr(const double[][4], double[4]);
void comQInDec(double [4], double[3]);
void displayFigures(const double[][4]);

// ****** MAIN ***************************************************
int main()
{
    double cSales[6][4];

    double incDecDivQrtr[6][3];
    double incDecComQrtr[3];
    double totalSalesPerQuarter[4]; // Add up the cols
    double aveDivSales[6];
    double highestQtr[4];

    getDivSales(cSales);
    divQIncDec(cSales, incDecDivQrtr);
    totSalesQrtr(cSales, totalSalesPerQuarter);
    averageDivSales(cSales, aveDivSales);
    highestDivisionQrtr(cSales, highestQtr);
    comQInDec(totalSalesPerQuarter, incDecComQrtr);
    displayFigures(cSales);

/*
    for(int r = 0; r < 6; r++)
    {
        for(int c = 0; c < 4; c++)
        {

        }
    }
*/

    return 0;
}

/* ------ Display Sales Figures ----------------------------------
Sales By Division
   -----------------------------------------------------------
   |      Q1      |      Q2      |      Q3      |      Q4    |
--------------------------------------------------------------
 1 |       123.21 |      $123.14 |      $123.5  |     $12.50 |
--------------------------------------------------------------
 2 |       123.21 |      $123.14 |      $123.5  |     $12.50 |
--------------------------------------------------------------
 3 |  $ 100000.21 |      $123.14 |      $123.5  |     $12.50 |
--------------------------------------------------------------
*/
void displayFigures(const double cSales[][4])
{
        cout << "displayFigures" << cSales[0][0] << endl << endl;

    cout << "\n\nSales By Division\n";
    cout << "   -------------------------------------------------------------\n";
    cout << "   |      Q1      |      Q2      |      Q3      |      Q4      |\n";
    cout << "----------------------------------------------------------------\n";

    for(int r = 0; r < 6; r++)
    {
        cout << setw(2) << right << r + 1 << " |";
        for(int c = 0; c < 4; c++)
        {
            cout << setw(13) << right << fixed << setprecision(2) << showpoint  << cSales[r][c] << " |";

            if(c == 3)
            {
                cout << endl;
                cout << "----------------------------------------------------------------\n";
            }
        }  cout << "displayFigures" << cSales[0][0] << endl << endl;

    }

}



/* ------ Division With Highest Sales Per Quarter ----------------
   The division with the highest sales for that quarter
----------------------------------------------------------------*/
void highestDivisionQrtr(const double cSales[][4], double qHigh[4])
{
    for(int r = 0; r < 6; r++)
    {

        qHigh[r] = cSales[r][0];
        for(int c = 1; c < 4; c++)
        {
            if(qHigh[r] < cSales[r][c])
            {
                qHigh[r] = cSales[r][c];
            }
        }
    }
    cout << "highestDivisionQrtr" << cSales[0][0] << endl << endl;
}

/* ------ Company Increase or Decrease by Quarter ----------------
    The company s increase or decrease from the previous quarter
    * NOTE (This will not be displayed for the first quarter.)
----------------------------------------------------------------*/
void totSalesQrtr(const double cSales[][4], double tCSales[4])
{
    for(int c = 0; c < 4; c++)
    {
        double tally = 0;
        for(int r = 0; r < 6; r++)
        {
            tally += cSales[r][c];
        }
        tCSales[c] = tally;
    }
    cout << "totSalesQrtr" << cSales[0][0] << endl << endl;
}

/* ------ Average Divisional Sales -------------------------------
     The average sales for all divisions that quarter
*/
void averageDivSales(const double cSales[][4], double average[6])
{


    for(int r = 0; r < 6; r++)
    {
        double tally = 0;
        for(int c = 0; c < 4; c++)
        {
            tally =+ cSales[r][c];
        }
        average[r] = tally/6;
    }
cout << "averageDivSales" << cSales[0][0] << endl << endl;
    return;
}


/* ------ Compant Wide Increase/Decease Per Quarter --------------
    The total sales for the quarter
*/
void comQInDec(double qSales[4],double incDecComQrtr[3])
{

    for(int i = 0; i < 3; i++)
    {
        incDecComQrtr[i] = qSales[i] - qSales[i + 1];
    }

}

/* ------ Divisional Increase or Decrease by Quarter -------------
    Each division s increase or decrease from the previous quarter
    * NOTE (This will not be isplayed for the first quarter.)
*/
void divQIncDec(const double cSales[][4], double incDec[][3])
{

    for(int r = 0; r < 6; r++)
    {
        for(int c = 0; c < 4; c++)
        {
            incDec[r][c] = cSales[r][c+1] - cSales[r][c];
        }
    }
    cout << "divQIncDec" << cSales[0][0] << endl << endl;

}


// ------ Get Diviosional Sales ----------------------------------
void getDivSales(double cSales[][4])
{
    double qSales = 0;


    for(int r = 0; r < 6; r++)
    {
        for(int c = 0; c < 4; c++)
        {
            cout << "\nPlease enter sales figure for divsion " << r + 1 << " quarter " << c + 1 << " : ";
            cin >> qSales;

            while(qSales < 0)
            {
                cout << "\nValue cannot be negative";
                cout << "\nPlease enter sales figure for divsion " << r+1 << " quarter " << c + 1 << " : ";
                cin >> qSales;
            }
            cSales[r][c] = qSales;
        }
    }
    cout << "getDivSales" << cSales[0][0] << endl << endl;
    return;
}







/*
   for(int r = 0; r < 6; r++)
    {
        for(int c = 0; c < 4; c++)
        {
            cout << "Division: " << r << " Quarter: " << c << " Sales: " << cSales[r][c] << endl;
        }
    }

     for(int r = 0; r < 6; r++)
    {
        for(int c = 0; c < 4; c++)
        {
            if(cSales[r][c] < cSales[r][c + 1])
            {
                incDec[r][c] = cSales[r][c+1] - cSales[r][c];
            }
            else if(cSales[r][c] > cSales[r][c + 1])
            {
                incDec[r][c] = cSales[r][c+1] - cSales[r][c];
            }
            else if(cSales[r][c+1] == cSales[r][c])
            {
                incDec[r][c] = 0;
            }
        }
*/

Update: The first function it hits after the function gettig input is changing the first value to the last value?

I was clobbering my array

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.