Blake Larsen
Blake Larsen

Reputation: 1

Error "argument type f "int" is incompatable with parameter of type "int*" and 'int assignVal(int[])': cannot convert argument 1 from 'int' to 'int[]'

For a class assignment I have to fill multiple array types with random numbers. Here is the code I have but keep getting the above error message:

Error "argument type f "int" is incompatable with parameter of type "int*" 
 and 'int assignVal(int[])': cannot convert argument 1 from 'int' to 'int[]' 

Any help is greatly appreciated, here the code:

#include <iostream>
using namespace std;

const int len = 5;

int assignVal(int array[len]);

int main()
{
    double arr1[len];
    int arr2[len];
    int arr3[len];

    assignVal(arr2[len]);

}
int assignVal(int array[len])
{
    for (int i = 0; i <= len; i++) 
    {
        array[i] = rand() % 10;
    }
}

Upvotes: 0

Views: 38

Answers (1)

Christophe
Christophe

Reputation: 73446

The problem is your call:

assignVal(arr2[len]); 

THis does not do what you think: it calls the function with the len-th element of arr2 array. So you try to pass an int element instead of the array.

Try:

assignVal(arr2); 

Upvotes: 1

Related Questions