-
same ol' problem
but new info. I know that I need a for loop to save the moves the user makes (tic tac toe for those of you who have no idea what im talking about). I have the entire program run out of a for loop that will end if it reaches 9 moves, but after each move the previous move is deleted from the memory. How do I make it stick in them memory? heres my source.
Code:
#include <iostream>
#include <string>
using namespace std;
void xturn();
void oturn();
void checkwin();
int board[9] = {0,1,2,3,4,5,6,7,8};
int playa[9] = {0,1,2,3,4,5,6,7,8};
int main()
{
int x, move, xx;
for (x=0; x<=8; x++)
{
if (playa[x] == 0 || playa[x] == 2 || playa[x] == 4 ||
playa[x] == 6 || playa[x] == 8)
{
cin >> move;
cout << "turn " << playa[x] << endl;
}
else
if (playa[x] == 1 || playa[x] ==3 || playa[x] == 5 ||
playa[x] == 7)
{
cout << "computer turn " << playa[x] << endl;
}
if (playa[x]==5)
{
cout << playa[0] << endl;
}
if (board[x] == 1 && board[x] == 2 && board[x] == 3)
{
cout << "WINNER!" << endl;
}
}
cout << "DRAW!!" << endl;
return 0;
}
void xturn()
{
int x, xx;
cin >> xx;
cout << "you move to square " << x << endl;
cout << playa[x] << endl;
}
void oturn()
{
int y;
cout << "computer not ready yet" << endl;
}
-
Well guys i think im a dumb ass. It was under my nose the entire time. All I had to do to save the input to the player array and board array was to write an if statement like this
Code:
cin >> move;
if(move == 1) //says if the user presses 1 then board[0]
board[0]=player[0]// is taken by player[0]
//and so on
//same for the o's
Im pritty sure thats all I have to do to save input to an array. Ok now on to a more interesting topic.......SPACE DETECTION!!!! Iv got a general idea of how to determine if a square is taken by x's or o's. Heres what I think....
Code:
if (board[0] == player[1] //o's )
//then you may not move there.....
Do yall think im on the right path?
-
Code:
if (board[0] == taken && board[1] == taken && board[2] == taken)
cout << "winner" << endl;
I waz wondering if anyone new why this piece of code wont work. It supposed to check for a winner. If there is someone in the 0 square and in the 1 square and in the 2 square it should say winner. But it only says winner if you input 0, 1, and 2 in that order. Any way I can fix this?