Thread: what's wrong with this code?

  1. #1
    Unregistered Leeman_s's Avatar
    Join Date
    Oct 2001
    Posts
    753

    what's wrong with this code?

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    void SetBoard(char board[][79], SHIP* player);
    void ShowBoard();
    
    int main()
    {
    	int keypress=0; //for player hitting a key
    
    	char board[51][79]; //board
    
    	struct SHIP //ship coordinate struct
    	{
    		int top0;
    		int top1;
    		int top2;
    		int top3;
    		int top4;
    		int top5;
    		int top6;
    		int top7;
    	};
    
    	SHIP playership;
    	playership.top0=38; //a & b coordinates for ship
    	playership.top1=49;
    
    	playership.top2=38;
    	playership.top3=50;
    
    	playership.top4=39;
    	playership.top5=50;
    
    	playership.top6=37;
    	playership.top7=50;
    
    	SHIP* player;
    	player=&playership; //for changing playership
    
    	SetBoard(board, player);
    
    	_getch();
    
    
    	return 0;
    }
    
    //*****************************************FUNCTIONS****************************************
    
    void SetBoard(char board[][79], SHIP* player)
    {
    	for(int a=0;a<=50;a++)     //initialize board
    	{
    		for(int b=0;b<=78;b++)
    		{
    			board[a][b]=' ';
    		}
    	}
    	board[player->top0][player->top1]='*';
    	board[player->top2][player->top3]='*';
    	board[player->top4][player->top5]='*';
    	board[player->top5][player->top7]='*';
    }
    I'm sure it's just a stupid error I made, like syntax. Thanks.

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    - What's the error message or problem you are getting?

    - If you have URL's in your sig, why not make the links?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User
    Join Date
    May 2002
    Posts
    21
    You are declaring your function
    Code:
    void SetBoard(char board[][79], SHIP* player);
    before you declare your struct SHIP. Correct code is:
    Code:
    #include <iostream.h>
    #include <conio.h>
    
    struct SHIP //ship coordinate struct
    	{
    		int top0;
    		int top1;
    		int top2;
    		int top3;
    		int top4;
    		int top5;
    		int top6;
    		int top7;
    	};
    	
    void SetBoard(char board[][79], SHIP* player);
    void ShowBoard();
    
    int main()
    {
    	int keypress=0; //for player hitting a key
    
    	char board[51][79]; //board
    
    	
    
    	SHIP playership;
    	playership.top0=38; //a & b coordinates for ship
    	playership.top1=49;
    
    	playership.top2=38;
    	playership.top3=50;
    
    	playership.top4=39;
    	playership.top5=50;
    
    	playership.top6=37;
    	playership.top7=50;
    
    	SHIP* player;
    	player=&playership; //for changing playership
    
    	SetBoard(board, player);
    
    	_getch();
    
    
    	return 0;
    }
    
    // *****************************************FUNCTIONS
    //****************************************
    
    void SetBoard(char board[][79], SHIP* player)
    {
    	for(int a=0;a<=50;a++)     //initialize board
    	{
    		for(int b=0;b<=78;b++)
    		{
    			board[a][b]=' ';
    		}
    	}
    	board[player->top0][player->top1]='*';
    	board[player->top2][player->top3]='*';
    	board[player->top4][player->top5]='*';
    	board[player->top5][player->top7]='*';
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what is wrong in this simple code
    By vikingcarioca in forum C Programming
    Replies: 4
    Last Post: 04-23-2009, 07:10 AM
  2. what is wrong with this code please
    By korbitz in forum Windows Programming
    Replies: 3
    Last Post: 03-05-2004, 10:11 AM
  3. I cant find what is wrong with this code
    By senegene in forum C Programming
    Replies: 1
    Last Post: 11-12-2002, 06:32 PM
  4. Anyone see what is wrong with this code?
    By Wise1 in forum C Programming
    Replies: 2
    Last Post: 02-13-2002, 02:01 PM
  5. very simple code, please check to see whats wrong
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 10-10-2001, 12:51 AM