# Thread: Function problems

1. ## Function problems

hey all, can someone please help me with my function error, i know that around the middle something is not working either, however this is just a small problem , does anybody see anything wrong with the function?, thankx ahead of time

Code:
```// cubidge, 2d-ness

#include <iostream.h>

#define MAXRAY 5

void display(int before, int[][]);	// function to display the square all good!!

int main()
{
int square[MAXRAY][MAXRAY];	// wont actually use all 5 spaces, some
int pos = 1;			// are for padding and collecting the side
int xpos, ypos;			// values..	       _               _
int xshif, yshif;			//			 1.  _|3|_     2.    _| |_
int spoto;				//	shif for   _|2|_|6|_	   _|2|7|6|_  = 15
//	 1		  |1|_|5|_|9| --> |_|9|5|1|_| = 15
//	   2	    |4|_|8|         |4|3|8|   = 15
//		 3		  |7|             |_|

// set to 0
for(int a=0; a < MAXRAY; a++)
for (int b=0; b < MAXRAY; b++)
square[a][b] = 0;

// make the first square
// ---------------------
// start in the center, spoto keeps position of the diagonal lines

spoto = 0;
xpos  = 0;
ypos  = 2;

// the shift in the center too..
xshif = 2;
yshif = 2;

while (pos < 10)
{
square[ypos][xpos] = pos;
pos++;
spoto++;

xpos += 1;
ypos -= 1;

// the first shift x, so we dont go over array and we stay on
// track
if (spoto == 3)
{
spoto = 0;

xpos = xshif;
ypos = yshif;

xshif -= 1;
yshif += 1;
}
}

//---
display(true, square);

for (int w=0; w < MAXRAY; w++)
if (square[w][0] > 0)
square[w][0] = square[w][3];

//---
display(false, square);

cout << "\n";
return 0;
}

// displays the square, passes before or after boolean type
void display(bool before, int a[][])
{
if (before == true)
cout << "---Before Magicalization---\n";
else
cout << "\n\n---After Magicalization---\n";

for (int y=0; y < MAXRAY; y++)
{
cout << "\n       |";
for (int z=0; z < MAXRAY; z++)
cout << a[y][z] << "|";
}
}```

comment at the top looks like this :S
Code:
```// wont actually use all 5 spaces, some
// are for padding and collecting the side
// values..	  _               _
//          1.  _|3|_     2.    _| |_
// shif for   _|2|_|6|_       _|2|7|6|_   = 15
//    1      |1|_|5|_|9| --> |_|9|5|1|_|  = 15
//      2      |4|_|8|         |4|3|8|    = 15
//        3	 |7|             |_|```

2. Yes, you have a type mismatch in your prototype, and your function definition specifies a multiple-subscripted array. Other than the first subscript, the size is required for all subsequent subscripts.

hth,

Popular pages Recent additions