Search code examples
c++arraysfunctionprototype

C++ 2d array... lost on prototype and calling don't see this anywhere


  1. I need help with the prototype.
  2. I need help with the caller.
  3. I need help with the function header.

I don't know how much more detail this site wants me to add, but the code speaks for itself, I am having trouble with the top three items but for some reason the site wants more context?

#include <iostream>
using namespace std;

void fillArray(int salesSheet[][COLSIZE], int rowSize);
// I dont know how to create prototype for 2d array
int main()
{
    const int ROWSIZE = 5, COLSIZE = 6;
    int salesSheet[ROWSIZE][COLSIZE], a, rowSize;

    fillArray(a[][COLSIZE], int rowSize);
    // I don't know where I messed this up 
    // I messed up the caller too, help?
    return 0;
}
void fillArray(int salesSheet[][COLSIZE], int rowSize)
{
    int r, c;
    cout <<"Enter sales report for each quarter, for your branch." << endl;
    for (c = 0; c < COLSIZE; c++) 
    {
        for (r = 0; r < rowSize; r++)
            cout << "\nBranch " << c+1 << " quarterly sales figures:"
        cin >> salesSheet[r][c];
    }
}

Solution

  • #include <iostream>
    using namespace std;
    
    const int ROWSIZE = 5, COLSIZE = 6;
    
    void fillArray(int salesSheet[][COLSIZE]);
    
    int main()
    {
    int salesSheet[ROWSIZE][COLSIZE];
    
    fillArray(salesSheet);
    
    return 0;
    }
    void fillArray(int salesSheet[][COLSIZE])
    {
    int r, c;
    cout <<"Enter the sales report for each quarter, in you branches column."    
    <<  endl;
    for (c = 0; c < COLSIZE; c++) 
        {
        for (r = 0; r < ROWSIZE; r++)
            {
                cout << "\nBranch " << c+1 << " quarterly sales figures:" ;
                cin >> salesSheet[r][c];    
            }
        }
    }