Function problems

This is a discussion on Function problems within the C++ Programming forums, part of the General Programming Boards category; hey all, can someone please help me with my function error, i know that around the middle something is not ...

  1. #1
    Registered User OxYgEn-22's Avatar
    Join Date
    Apr 2002
    Posts
    36

    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|             |_|
    Last edited by OxYgEn-22; 04-12-2002 at 07:18 AM.
    Is that air you're breathing?

  2. #2
    Ted
    Ted is offline
    Registered User
    Join Date
    Aug 2001
    Posts
    52
    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 subscribe to a feed

Similar Threads

  1. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Problems with str.replace function
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 02:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21