Passing array as function argument

Here is my code. When I run this, it shows
|29|error: invalid conversion from ‘int’ to ‘int*’ [-fpermissive]|

Why?

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
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int gradeCalc(int t1, int t2, int f, int a, int ct[])
{
    int sum=0;
    sort(ct, ct+3);

    sum = ct[0]+ct[1];

    return sum;
}

int main()
{
    int n;

    for(int i=1; ;i++)
    {
        int t1,t2,f,a,ct[3];

        scanf("%d %d %d %d",&t1,&t2,&f,&a);
        for(int i=0; i<3; i++)
            scanf("%d",&ct[i]);

        cout<<gradeCalc(t1,t1,t2,f,a,ct);
    }

    return 0;
}
You're passing t1 twice, so the only problem is you're just passing too many arguments. Simple mistake that happens to us all. :P
Try:

cout<<gradeCalc(t1,t2,f,a,ct);
Last edited on
Topic archived. No new replies allowed.