I'm having trouble passing off the 2D array called "sales" to a function. Any idea what I'm doing wrong? I have C++ as an online class and my teacher is no help :( The error message I'm getting is:
no instance of overloaded function "getTotal" matches the argument list as well as "COLS": undeclared identifier
getTotal function does not take 2 arguments"
// Week 7 Assignment 2
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototypes
int getTotal(int[][COLS]);
// Global Variables
const int ROWS = 4;
const int COLS = 4;
const int NUM_DIVS = 5;
const int NUM_QTRS = 5;
int sales[ROWS][COLS];
int totalSales;
string division[NUM_DIVS] = { "North", "South", "East", "West", "Quarter Total" };
string quarters[NUM_QTRS] = { "Quarter 1", "Quarter 2", "Quarter 3", "Quarter 4" };
int total;
int main()
{
// Variables
cout << "This program will calculate information about sales during a year." << endl;
// Loops to fill the array
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the North during Quarter " << (count + 1) << ": $";
cin >> sales[0][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the South during Quarter " << (count + 1) << ": $";
cin >> sales[1][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the East during Quarter " << (count + 1) << ": $";
cin >> sales[2][count];
}
for (int count = 0; count < COLS; count++)
{
cout << "Please enter the sales for the West during Quarter " << (count + 1) << ": $";
cin >> sales[3][count];
}
total = getTotal(sales, 4);
return 0;
}
// Function to get the total of everything in the array
int getTotal(int sales[][COLS])
{
int totAl = 0;
for (int count = 0; count < ROWS; count++)
{
for (int count = 0; count < COLS; count++)
totAl += sales[count][count];
return totAl;
}
}