The problem I am having is the computer does not switch turns after it inputs a move, infact the computer endlessly inputs the move.
//This program is a tic tac toe program
//include the following libraries
#include "stdafx.h"
#include<iostream>
#include<string>
#include<ctime>
//use standard namespace
using namespace std;
//declare global variables
char board[9];
//declare functions
void showboard();
bool moveisvalid(int m);
int whowon();//returns 0 if no one won, 1 if player 1 won, 2 if player 2 won
void main ()
{
//declare local variables
string player_name_1;
srand(time (NULL));
int player_name_2=rand()% 8+1;
int whose_turn=1; //this variable states that it is player 1's turn, if the value is set to 2 it is player 2's turn
int move;//this variable stores the players position as a result of the last move
int totalmoves=0;//keaps trac of the total amount of moves
//tell players to input their names
cout<<"Player 1, please enter your name"<<endl;
cin>>player_name_1;
//call the board outside main
//run this function untill the player chooses a valid move
while(whowon()==0 && totalmoves<9)
{
do
{
showboard();
//tells which player move it is
if(whose_turn==1)
{
cout<< player_name_1<<" make a move."<<endl;
cin>>move;
}
else
{
player_name_2;
}
//get the players position of the move he inputed
}
while(moveisvalid (move) !=true);
//add 1 to the total amount of moves every time a move is valid
totalmoves++;
//change whose turn it is
switch(whose_turn)
{
case(1):
{
board[move]='x';
You are just reading the move from the first player. Let's say I enter 2 for my move. It's gonna display x in position 2 and then just keep on displaying the board over and over, because the other player is not making move!
consider revising this part
1 2 3 4 5 6 7 8 9 10 11
if(whose_turn==1)
{
cout<< player_name_1<<" make a move."<<endl;
cin>>move;
}
else
{
player_name_2;
}
//get the players position of the move he inputed
}