Hi I'm just wondering if anyone can tell me if there is something wrong with the way I am using the do while loop in my function GetIntInput().
This is a part of my program for tic tac toe. It compiles fine and runs but the problem I have is that my condition that the user and computer cannot place thier character 'X' or 'O' in the array at a location that doens't have ' ' in it ( I pound defined ' ' to be EMPTY)
But when the program executes the user can write over his own character and the computers. I highlighted the loop I think is the cause of the problem but I don't see why it isn't working.
Any thoughts??
Thank you!
Code:/******************************************************************************* ******************************************************************************** This function is for the users turn *******************************************************************************/ void userturn(char TTTboard[]) { int SquareNumber; /*Number corresponding index array (TTTboard[]) SquareNumber=GetIntInput(TTTboard); writetoboard(TTTboard, SquareNumber,USER); DisplayTTTBoards(TTTboard); } /******************************************************************************* ******************************************************************************** This function gets a valid integer input from the user. PRE: User has been prompted to enter an integer and min <= max. POST: an integer value, i, entered by user is returned, where min <= i <= max. */ int GetIntInput(char TTTboard[]) { int i; do { printf("\n\nPlease enter number of the square you would like to place your 'O' in:"); while(scanf("%i", &i) != 1) /* get rid of the characters that were entered */ { clearInputStream(); printf("\nThat is not valid. Please enter a valid location on the board: "); } /* clear the input stream again, in case extra characters after the integer were entered */ clearInputStream(); }while(ValueInRange(i,MIN,MAX)==FALSE && TTTboard[i]==COMPUTER && TTTboard[i]==USER); return i; } /******************************************************************************* ******************************************************************************** This function determines if a value is within a range. PRE: min <= max and value is defined POST: returns true if min <= value <= max, and false otherwise. *******************************************************************************/ int ValueInRange(int value, int min, int max) { if(min <= value && value<= max) return TRUE; else return FALSE; }