4 Replies - 537 Views - Last Post: 20 February 2011 - 12:05 AM Rate Topic: -----

#1 Guest_Ajay birbal*


Reputation:

functions are not being executed?

Posted 19 February 2011 - 11:51 PM


#include <iostream>
using namespace std;

char board[3][3] ; // board a global variable, can be accessed by all functions in this program

void boardinit () //Intializes board
{
     for (int i = 0 ; i < 3 ; i++)
	     for(int j = 0; j < 3; j++)
		         board[i][j] = '-'; 
}

void showboard () // prints the board on screen
{
     cout << board[0][0] << " | " << board[0][1] << " | " << board[0][2] << endl;
     cout << board[1][0] << " | " << board[1][1] << " | " << board[1][2] << endl;
     cout << board[2][0] << " | " << board[2][1] << " | " << board[2][2] << endl;
}



int main()
{

    cout << "Welcome to C++ tic tac toe game !!!" << endl;
    cout << "Initializing board please wait : " << endl;
    void boardinit ();
    void showboard ();
    cout << "Game begins : " << endl;

    system("pause");


}



Why the functions are not being executed?Why the board is not printing?

Is This A Good Question/Topic? 0

Replies To: functions are not being executed?

#2 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5355
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Re: functions are not being executed?

Posted 19 February 2011 - 11:53 PM

I would be quite surprised that this code compiles.

Inside of main you have these two lines :

Quote

    void boardinit ();
    void showboard ();


You don't define your functions inside of main. In fact you have already defined them above main, which is correct. Update the lines to the following, recompile, & run your program. See if that helps you.

    boardinit();
    showboard();


** Renamed title to be more meaningful **
Most topics posted on this site are asking for some level of help or assistance. Giving your topic a title of "Help me" does not describe the problem, & gives little reason for others to read your post.
Was This Post Helpful? 0
  • +
  • -

#3 Salem_c  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1689
  • View blog
  • Posts: 3,209
  • Joined: 30-May 10

Re: functions are not being executed?

Posted 19 February 2011 - 11:55 PM

Please don't take the rapid response to your question has having anything to do with your rubbish topic title.
http://www.catb.org/...html#bespecific

> 27 void boardinit ();
This is a prototype for a function (a declaration).

boardinit();

This is a function CALL.
Was This Post Helpful? 0
  • +
  • -

#4 Guest_Ajay birbal*


Reputation:

Re: functions are not being executed?

Posted 20 February 2011 - 12:04 AM

Thanks for repying me no2pencil, that was really fast man.
Now function works.
Was This Post Helpful? 0

#5 no2pencil  Icon User is online

  • Admiral Fancy Pants
  • member icon

Reputation: 5355
  • View blog
  • Posts: 27,314
  • Joined: 10-May 07

Re: functions are not being executed?

Posted 20 February 2011 - 12:05 AM

Glad to see that worked out for you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1