Question about restarting a loop
I finished my ttt game, its version 1.0. I decided that once somebody has won I want to ask them if they want to play again. How would you go back into a loop once you left it? Here is my code:
Code:
#include <stdio.h>
#include <windows.h>
int turn = 1, move = 0, done = 0; // Sets turn to 1, move to 0, and done to 0
char restart, y, Y;
char name1[25], name2[25];
char board[9]; // The tic-tac-toe Board
void DrawBoard();
void DrawBoard() //* Draws the board *//
{
printf("\n\n");
printf(" %c | %c | %c \n", board[0], board[1], board[2]);
printf(" --------- \n");
printf(" %c | %c | %c \n", board[3], board[4], board[5]);
printf(" --------- \n");
printf(" %c | %c | %c \n", board[6], board[7], board[8]);
printf("\n\n");
}// DrawBoard
void Wincheck()
{
if ((board[0] == 'X' && board[1] == 'X' && board[2] == 'X') ||
(board[3] == 'X' && board[4] == 'X' && board[5] == 'X') ||
(board[6] == 'X' && board[7] == 'X' && board[8] == 'X') ||
(board[0] == 'X' && board[3] == 'X' && board[6] == 'X') ||
(board[1] == 'X' && board[4] == 'X' && board[7] == 'X') ||
(board[2] == 'X' && board[5] == 'X' && board[8] == 'X') ||
(board[0] == 'X' && board[4] == 'X' && board[8] == 'X') ||
(board[2] == 'X' && board[4] == 'X' && board[6] == 'X'))
{printf("%s wins\n", name1);
done = 1;}
if ((board[0] == 'O' && board[1] == 'O' && board[2] == 'O') ||
(board[3] == 'O' && board[4] == 'O' && board[5] == 'O') ||
(board[6] == 'O' && board[7] == 'O' && board[8] == 'O') ||
(board[0] == 'O' && board[3] == 'O' && board[6] == 'O') ||
(board[1] == 'O' && board[4] == 'O' && board[7] == 'O') ||
(board[2] == 'O' && board[5] == 'O' && board[8] == 'O') ||
(board[0] == 'O' && board[4] == 'O' && board[8] == 'O') ||
(board[2] == 'O' && board[4] == 'O' && board[6] == 'O'))
{printf("%s wins\n", name2);
done = 1;}
}
void Playersturn();
void Playersturn() // Players turn
{
// player 1
if(turn == 1)
{printf("It is %s's turn: ", name1);
scanf("%d", &move);
move--;
if( (board[move]!='X')&&(board[move]!='O') )
{board[move]='X';turn=2;}
else
printf("Invalid Move\n");
system("cls");
}// player 1
// player 2
else
{printf("It is %s's turn: ", name2);
scanf("%d", &move);
move--;
if( (board[move]!='X')&&(board[move]!='O') )
{board[move]='O';turn=1;}
else
printf("Invalid move\n");
system("cls");
} //player 2
} //players turn
int main()
{
printf("\n");
printf("Welcome to tic-tac-toe!!!\n\n");
// Players names
printf("What is 1st player's name: ");
scanf("%s", name1);
printf("\nWhat is 2nd player's name: ");
scanf("%s", name2);
system("cls");
do
{
DrawBoard();
Playersturn();
Wincheck();
} // do loop
while (done == 0);
return 0;
}// int main()