text: I am in a beginners programming course, and we have been doing C programs up until now, and the first C++ program we have confused me a bit. We have to make a simple tic tac toe program that plays against you [it doesn't have to be great at playing, it just has to work]. Since I have only done much simpler C++ programs before [simple math and printing to the screen is all I am familiar with] I have no idea how I would make it accept input properly form the user, nor keep up with what boxes of the play field are occupied with an X or an O. Below I've posted my teacher's example, and the only part I fully understand is the loop that sets the board to blank to start the game, and where the playing board is printed to the screen with the variables ready to be manipulated for game play. Any insight anyone could give on this would be very much appreciated! Here is the code.
  #include <cstdlib> #include <stdio.h> class TicTac { char board[9]; //Tic Tac Toe board public: TicTac(); //Constructor void draw_board(); //draw the current board on the screen }; //Constructor TicTac::TicTac(){ for(int i=0; i<9; i++) //initialize board to blank board[i]=' '; } void TicTac::draw_board(){ system("cls"); printf("_____________\n"); printf("| %c | %c | %c |\n", board[6], board[7], board[8]); printf("_____________\n"); printf("| %c | %c | %c |\n", board[3], board[4], board[5]); printf("_____________\n"); printf("| %c | %c | %c |\n", board[0], board[1], board[2]); printf("_____________\n"); } main(){ TicTac my_game; my_game.draw_board(); system("pause"); }