too few arguments to function 'int getData (int)'

not sure what's going on. I'm trying to pass a single argument to a function for the purpose of collecting appropriate data from the user. The code reads:

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
#include <iostream>
#include<iomanip>
using namespace std;


//Global constants
const int COLUMNS = 7;
const int ROWS = 36;

//function prototypes
int getData(int);

int main()
{
    const int COLUMNS = 7;
    int rows,               //for input number of students
        lines,              //for looping
        cols;               //for looping

    string data(const int [ROWS][COLUMNS], int);

    cout << "How many students do you \n"
         << "wish to enter grades for? ";
    cin >> rows;

    //loop to get data
    for (lines = 0; lines < rows; lines++)
    {
        for(cols = 0; cols < COLUMNS - 1; cols++)
        {
            getData(cols);
            getData() >> data[rows][cols];
            cout << data[rows][cols]
        }
    }
    return 0;
}


Any ideas?
I think you mean this?
 
data[rows][cols] = getData(cols);

Last edited on
tried that, it gives me an error:

warning: pointer to a function used in arithmetic

and won't compile.
Where have you defined the int getData (int) function? I can only see the prototype?
I hadn't included it, because compiling errored out prior to getting there, but here it is:

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
int getData(int column)
{
    arrDat = 0
    if (column == 0)
    {
        cout << "Last Name: ";
        cin >> arrDat;
    }
    else if (column == 1)
    {
        cout << "First name: ";
        cin >> arrDat;
    }
    else if (column == 2)
    {
        cout << "ID number: "
        cin >> arrDat;
    }
    else
    {
        cout << "Test score: ";
        cin >> arrDat;
    }
    return arrDat;
}
OK, so I'm taking a new tack with this:

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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
#include<iomanip>
using namespace std;


//Global constants
const int COLUMNS = 7;
const int ROWS = 36;

//function prototypes
void getData();
void alpha(int [][COLUMNS]);

int main()
{
    getData();

    return 0;
}

void getData()
{
    int rows,               //for input number of students
        lines,              //for looping
        cols;               //for looping


    string data [ROWS][COLUMNS];

    cout << "How many students do you \n"
         << "wish to enter grades for? ";
    cin >> rows;

    //loop to get data
    for (lines = 0; lines < rows; lines++)
    {
        for(cols = 0; cols < COLUMNS - 1; cols++)
        {
            if (cols == 0)

            {
                cout << "Last Name: ";
                cin >> data[lines][cols];
            }
                else if (cols == 1)
            {
                cout << "First name: ";
                cin >> data[lines][cols];
            }
                else if (cols == 2)
            {
                cout << "ID number: ";
                cin >> data[lines][cols];
            }
                else
            {
                cout << "Test score: ";
                cin >> data[lines][cols];
            }
        }
    }
    for (int test = 0; test < rows; test++)
    {
        for(int test2 = 0; test2 < COLUMNS - 1; test2++)
        {
            cout << data[test][test2] << "\t";

        }
    }

    alpha(data);

}

void alpha(string alphaArray[ROWS][COLUMNS])
{

    for (int test = 0; test < rows; test++)
    {
        for(int test2 = 0; test2 < COLUMNS - 1; test2++)
        {
            cout << alphaArray[test][test2];
        }
}


but now the highlighted function call above gives me this:

error: cannot convert 'std::string (*)[7]' to 'int (*)[7]' for argument '1' to 'void alpha(int (*)[7])'


why? can anyone tell me?
Function prototype for void alpha() is wrong.

Wrong:
void alpha(int [][COLUMNS]);

Correct:
void alpha(string alphaArray[ROWS][COLUMNS]);

That's why it shows "cannot convert from std::string to int"

To fix the problem with GetData(int), you should use a string variable to store the data and return the input as string too, because you're storing it in a 2D string array anyway.

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
string getData(int column)
{
    string arrDat = "";
    if (column == 0)
    {
        cout << "Last Name: ";
        cin >> arrDat;
    }
    else if (column == 1)
    {
        cout << "First name: ";
        cin >> arrDat;
    }
    else if (column == 2)
    {
        cout << "ID number: "
        cin >> arrDat;
    }
    else
    {
        cout << "Test score: ";
        cin >> arrDat;
    }
    return arrDat;
}
Last edited on
Topic archived. No new replies allowed.