Can not call a function in main?

Why I cannot call the inputByRows function??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

const int NUMBER_OF_COLUMNS = 7;
const int NUMBER_OF_ROWS = 5;
int row, col;

void inputByRows (double arr[row][col]); //To input the 8 numbers via row processing
void outputByColumns (); // output the 8 numbers via column processing

int main() {
    
    double array[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]; // stores 8 numbers
    inputByRows(array);  //Here the xcode shows there is no matching for it!!!
    outputByColumns();
    
    return 0;
}
//input the array by row processing
void inputByRows(double arr[row][col])
{
    ifstream rock;
    rock.open("2DArray.txt");
    if (!rock)
    {
        cout << "Error to open the file.";
        return;
    }
    cout << "Please input the 8 numbers: " << endl;
    for (int col=0; col<NUMBER_OF_COLUMNS; col++)
        for (int row=0; row<NUMBER_OF_ROWS; row++)
            rock >> arr[row][col];
    rock.close();
}
//output the array by column processing
void outputByColumns(double arr[row][col])
{
    for (int row=0; row<NUMBER_OF_ROWS; row++)
        for (int col=0; col<NUMBER_OF_COLUMNS; col++)
            cout << arr[row][col] << " ";
    cout << endl;
}
row and column have to be constants. You also didn't properly declare or use outputByColumns. Since it's not much, I fixed it for you.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <fstream>
#include <cassert>
using namespace std;

const int NUMBER_OF_COLUMNS = 7;
const int NUMBER_OF_ROWS = 5;

void inputByRows (double arr[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]); //To input the 8 numbers via row processing
void outputByColumns (double arr[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]); // output the 8 numbers via column processing

int main()
{
    double array[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS]; // stores 8 numbers
    inputByRows(array);  //Here the xcode shows there is no matching for it!!!
    outputByColumns(array);
    
    return 0;
}
//input the array by row processing
void inputByRows(double arr[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS])
{
    ifstream rock;
    rock.open("2DArray.txt");
    if (!rock)
    {
        cout << "Error to open the file.";
        return;
    }
    cout << "Please input the 8 numbers: " << endl;
    for (int col=0; col<NUMBER_OF_COLUMNS; col++)
        for (int row=0; row<NUMBER_OF_ROWS; row++)
            rock >> arr[row][col];
    rock.close();
}
//output the array by column processing
void outputByColumns(double arr[NUMBER_OF_ROWS][NUMBER_OF_COLUMNS])
{
    for (int row=0; row<NUMBER_OF_ROWS; row++)
        for (int col=0; col<NUMBER_OF_COLUMNS; col++)
            cout << arr[row][col] << ' ';
    cout << endl;
}
Thank you so much, Yay295!!~ It works well!!~
Topic archived. No new replies allowed.