I added the void gboard function before i added the code to allow the users to enter where they would like to place their piece and it was working. Since then, it stopped working and Ive tried lots to fix it, i dont know if im just missing a simple mistake or what. I havnt added any code to check if a player has won, but i will get that done soon, i just need to overcome this problem first. Any help would be greatly appreciated, thanks:
Errors:
1>.\Coursework3.cpp(22) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>.\Coursework3.cpp(229) : error C2062: type 'void' unexpected
1>.\Coursework3.cpp(230) : error C2143: syntax error : missing ';' before '{'
// Coursework3.cpp : main project file.
#include "stdafx.h"
#include <iostream>
#include <time.h>
#include <string>
#include <cstdlib>
#include <stdlib.h>
using namespace std;
void gboard();
int store, store1, count, player, turn;
int gameboard [3][3];
string player1 = player1;
string player2 = player2;
char start;
int main()
{
srand ( time(NULL));
cout << "Hello, and welcome to the game of Naughts and Crosses.\n";
cout << "A random select has chosen who will go first, and who will play as O and who will play as X.\n\n";
player = rand() % 2 + 1;
count = 1;
store = 0;
do
{
store1 = 0;
do
{
gameboard[store][store1] = count;
count++;
store1++;
} while (store1 < 3);
store++;
} while (store <3);
cout << "Instructions: This is the layout of the Naughts and Crosses board. You enter a number which corresponds to the place on the board.\n";
cout << "These are the different ways in which you can win. You must get 3 of your piecesin a row.\n\n";
cout << " Start Win Win Win Draw \n";
cout << " 1 2 3 O O O O 2 3 1 2 O O O X \n";
cout << " 4 5 6 - 4 5 6 - O 5 6 - 4 O 6 - X X O \n";
cout << " 7 8 9 7 8 9 O 8 9 O 8 8 O X O \n";
do
{
cout << "When you are ready enter 's' to start the game, if you would like to quit enter 'q'.\n";
cin >> start;
start = tolower(start);
if (start == 's')
{
system("cls");
gboard();
if (player == 1)
cout << "Player 1's turn first. \n\n";
else
cout << "Player 2's turn first. \n\n";
if (player == 1)
{
cout << "Player1: 0 \n";
cout << "Player2: X \n\n";
}
else
{
cout << "Player1: X \n";
cout << "Player2: O \n\n";
}
cout << "player " << player << "'s turn, please enter where you would like to place your piece: \n";
do
{
do
{
turn = 0;
cin >> turn;
store1 = 0;
if (turn < 1 )
cout <<"move is less than 1";
cin >> start;
if (turn > 9)
cout << "move is greater than 9";
cin >> start;
}while ((turn < 1) || (turn > 9));
switch (turn)
{
case 1:
if (gameboard[0][0] <=9)
{
gameboard[0][0] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 2:
if (gameboard[0][1] <=9)
{
gameboard[0][1] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 3:
if (gameboard[0][2] <=9)
{
gameboard[0][2] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 4:
if (gameboard[1][0] <=9)
{
gameboard[1][0] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 5:
if (gameboard[1][1] <=9)
{
gameboard[1][1] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 6:
if (gameboard[1][2] <=9)
{
gameboard[1][2] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 7:
if (gameboard[2][0] <=9)
{
gameboard[2][0] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 8:
if (gameboard[2][1] <=9)
{
gameboard[2][1] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
case 9:
if (gameboard[2][2] <=9)
{
gameboard[2][2] = player*1000;
}
else
{
cout << "You cannot place your piece here, slot is taken";
store1 = 1;
}
break;
default:
cout << "You have entered an incorrect place";
cin >> store;
}
if (start == 'q')
exit(0);
else
{
system("cls");
cout << "You have entered an incorrect choice please enter your choice again.";
}
}while (( start != 's') || (start != 'q'));
}
return 0;
}
void gboard()
{
store = 0;
store1 = 0;
do
{
store1 = 0;
do
{
if (gameboard[store][store1] > 9)
if (gameboard[store][store1] == 1000)
{
cout <<" X ";
}
else if (gameboard[store][store1] == 2000)
{
cout << " O ";
}
else;
else if (gameboard[store][store1] < 100)
{
cout << gameboard[store][store1] << " ";
}
store1++;
if (store1 < 3) cout << "| ";
} while (store1 < 3);
if (store < 2)
{
cout << "\n";
cout << " | |\n";
cout << "---|-----|---\n";
cout << " | |\n";
}
store++;
}while (store < 3);
cout << "\n\n\n\n";
}
This post has been edited by lukeyboyuk: 14 January 2009 - 08:51 AM

New Topic/Question
Reply




MultiQuote




|