I'm trying to make a simple tic-tac-toe program. In the example below, it's incomplete, only I finished it enough to run it and check for errors.
When I run it, no matter what number I put in, it always displays array[i] (i being whatever number I put in), as the number it originally was, not 'X', as it should be. As you can see, I declare the array numbers outside of while(playagain=='y'), so it shouldn't redefine them after looping. Please help.Code:#include <iostream.h> #include <stdio.h> #include <time.h> char playagain='y'; int number; char array[10]; int main(void) { array[1]='1'; array[2]='2'; array[3]='3'; array[4]='4'; array[5]='5'; array[6]='6'; array[7]='7'; array[8]='8'; array[9]='9'; while(playagain=='y') { cout << array[1]; cout << "|"; cout << array[2]; cout << "|"; cout << array[3]; cout << "\n-----\n"; cout << array[4]; cout << "|"; cout << array[5]; cout << "|"; cout << array[6]; cout << "\n-----\n"; cout << array[7]; cout << "|"; cout << array[8]; cout << "|"; cout << array[9]; cout << "\n"; cout << "Please enter the number of the space you would like to place an X in: "; cin >> number; for(int i=1;i<10;i++) { if(number==array[i]) { array[i]='X'; } } } return 0; }



LinkBack URL
About LinkBacks


