The problem I am having is the computer does not switch turns after it inputs a move, infact the computer enlessly inputs the move.
//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';