'a' was not declared in this scope. I can't spot the error. Pls advise.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

const int MAX = 10;


void constructArray_2 (int*, int);


int main ()
{
       
	srand (time (NULL));
    constructArray_2 (a, MAX);
      
}
void constructArray_2 (int *a, int size)
{
	for (int i = 0; i < size; i++)
	{
		*a = rand () % 10;
		++a;
	}
}

constructArray_2 (a, MAX); You are passing in the value a to your function but there is no a defined in main(). Where is this value supposed to come from?

constructArray_2 (a, MAX); You are passing in the value a to your function but there is no a defined in main(). Where is this value supposed to come from?

Ok tks. I forgot to include "int a [MAX];" in main function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.