Search code examples
c++arraysfunctioncall

I have another simple C++ concern calling to a function with an array as a parameter? I keep getting an error


I have a very simple question that I'm sure can be answered quite easily, but google is not exactly yielding results that are helping rectify the error I am receiving.

I have a simple single-dimension array consisting of 100 integers. I am required to use another function to "fill" the array, so to speak.

While in main I am trying to make a simple call to the function that will "fill" the array with random integers.

However, I have written the call-to as such:

fillArray (int list[], int number);

With number being the # of random integers to store in the array. These parameters cannot change.

I keep receiving the error message:

"Expected '(' for function-style cast or type construction.

I have only been in my C++ class for 5 weeks now and I really have no idea what that means. I'm self taught for the most part in CSS, VBA, MySQL, and HTML of course. So I'm not as...intuitive when it comes to translating error messages.

Spent a while trying to google what exactly it meant and all the codes were way beyond my scope of understanding haha.

Here is my declaration of the function that I have within my main function (this is a requirement).

void fillArray(int, int);

And my function header:

void fillArray (int array[], int n)

I do not have anything written in the fillArray function as of yet. Could that be the reason for the error? If it is I will likely feel a bit foolish. :")


Solution

  • You code should have the following structure:

    void fillArray(int[], int);
    
    int main()
    {
        //...write code to create array here ...
    
        //this is how you call the function
        fillArray (list, number);   
    
    }
    
    
    
    void fillArray (int list[], int number)
    {
        //...write your implementation of fillArray here
    }