Hi!
I am trying to declare a global array for use throughout a program. The program is a math question generator (sets).
My 'main' program is as follows:-
Code:
#include <cstdlib>
#include <iostream>
#include <ctime>
using namespace std;
int arrayname[9];
int main()
{
srand((unsigned)time(0));
int random_integer;
cout << "Given the sets A and B, where:-" << endl << endl << endl << "A = {";
for(int index=0; index<5; index++)
{
random_integer = (rand()%9)+1;
arrayname[index] = random_integer;
cout << arrayname[index] << ", ";
}
cout << "}" << endl << endl << "and" << endl << endl << "B = {";
for(int index=6; index<10; index++)
{
random_integer = (rand()%9)+1;
arrayname[index] = random_integer;
cout << arrayname[index] << ", ";
}
cout << "}";
cout << arrayname[index] << "test";
cout << endl << endl << endl << endl;
system("pause");
}
I have never created another file for use during a program, I found a tutorial saying I should declare the global array in a separate header file, I've made this:-
Code:
#include <iostream>
using namespace std;
int index = 0;
extern int arrayname[index];
The header file is reporting that "'index' : undeclared identifier".
I understand global arrays are baaddd, but I'm wanting to use one at present, so in summary I'm looking for some advice on how to setup the global file correctly.
Many thanks for any advice!
Swerve.