"sales"という2次元配列を関数に渡すときに問題があります。私が間違っていることは何か考えていますか?私はオンラインクラスとしてC++を持っていないし、私の先生は何の助けではありません:(私は取得していますエラーメッセージは次のとおりです。2D配列をエラーメッセージなしの関数に渡すことができませんC++
オーバーロードされた関数のインスタンスを「getTotalは、」引数 リストだけでなく、「COLS」にマッチ:宣言されていない識別子
getTotalあなたはdefiniでいることを修正して、それが定義されており、あなたがそれを行うことができない前に、あなたが
COLS
を使用している2つの引数「
// 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;
}
}
変数を使用する前に宣言する必要があります。最初に 'COLS'を使い、宣言します。 – nwp
あなたが言及したエラーとは別に、コードに別のバグがあります。あなたの関数は、最初の行の和を返します – user463035818
[C++関数に2次元配列を渡す]可能な複製(http://stackoverflow.com/questions/8767166/passing-a-2d-array-to-ac-function ) –