populateing an array with for loops
Hi there
I'm just starting out with c++, its difficult but I'm getting there. Anyway here's my problem.
the code i'm writing is meant to declare an uninitiilized array and then populate it to make a pattern and thern print it out. Heres my code
Code:
#include<iostream>
using namespace std;
char populate(char, int, int);
char display(char, int, int);
int main()
{
//declare the i and j variables for use in the array
//declare the array and leave it uninitalized
//Call the functions populate() and display()
int i, j;
char array1[7][7];
char populate(array1, i, j);
char display(array1, i, j);
return 0;
}
//function that uses a for loop to add a 1 the the element of the array if i is greater
//that j and a 0 if the opposite is true
char populate(char array2, int i, int j)
{
for (i=0; i<7; i++)
{
for (j=0; j<7; j++)
{
if (i<j)
array2[i][j]=1;
else
array2[i][j]=0;
}
}
}
//function that prints out the contents of the array
char display(char array3, int i, int j)
{
for(i=0; i<7; i++)
{
for(j=0; j<7; j++)
{
cout<< array3[i][j];
}
}
}
and heres the error messages the compiler is throwing out;
In function ‘int main()’:
21: error: initializer expression list treated as compound expression
23: error: initializer expression list treated as compound expression
In function ‘char populate(char, int, int)’:
39: error: invalid types ‘char[int]’ for array subscript
41: error: invalid types ‘char[int]’ for array subscript
In function ‘char display(char, int, int)’:
57: error: invalid types ‘char[int]’ for array subscript
I've been told that I'm not calling/defining my functions correctly, but they didn't say how. Also i'm not sure if saying 'array2' and 'array3' would affect it in any way, but it throws out the error messages regardless of what i call them
thanks in advance
ES