Apr 7, 2012 at 11:28am UTC
I dunno what to do with this 1 error pls help me out
#include <iostream>
#include <stdib.h>
void welcome();
void instructions();
void game();
void about();
void ask();
void main()
{
welcome();
}
void instructions(){
cout<<"general instraction"<<endl;
cout<<"tic toc toe is very simple game"<<endl;
cout<<"it simplie played with two Player"<<endl;
cout<<"one of the user need to complete the txt"<<endl;
cout<<"then the first one who finish complete the txt will be declare a winner"<<endl;
ask();
}
void about(){
cout<<"The following Programer are: "<<endl;
cout<<"Adrian Sebastian"<<endl;
cout<<"Garner Hagonoy"<<endl;
ask();
}
void ask(){
int num;
cout<<"\n\n\t\tPress 1 menu \t Press 2 Exit"<<endl;
cout<<"\t\tEnter:";
cin>>num;
if(num==1){
system("cls");
welcome();}
else
cout<<"\t\t\tGood Bye"<<endl;
cout<<"\t\t";
}
void welcome(){
int num;
cout<<"_______________________________________________________________________________";
cout<<"_________________________________________________________________________________\n";
cout<<"\n\t\t\t \5\5\5\5\5 Welcome User! \5\5\5\5\5\n\n";
cout<<"_______________________________________________________________________________";
cout<<"_________________________________________________________________________________\n";
cout<<"\t\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\n\n";
cout<<"\t\t\tLet's Play Rock,Scissors,Paper!\t\n\n";
cout<<"\t\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\4\n\n";
cout<<"\n\t\t\t\t MAIN MENU\n\n";
cout<<"\t\t\t 1. New Game \t 2. Instructions\n";
cout<<"\t\t\t 3. About \t 4. Exit\n";
cout<<"\n\n\t\t Please Enter Your Choice:";
cin>>num;
if(num==1){
system("cls");
game();
}
else if(num==2){
system("cls");
instructions();
}
else if(num==3){
system("cls");
about();}
else if(num==4){
system("cls");
cout<<"Good Bye!!!";
}}
void game(){
char cSquare1('1');
char cSquare2('2');
char cSquare3('3');
char cSquare4('4');
char cSquare5('5');
char cSquare6('6');
char cSquare7('7');
char cSquare8('8');
char cSquare9('9');
int iPlayerTurn(1);
bool bGameOver(true);
do {
// Print board
std::cout << cSquare1 << "|" << cSquare2 << "|" << cSquare3 << std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << cSquare4 << "|" << cSquare5 << "|" << cSquare6 << std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << cSquare7 << "|" << cSquare8 << "|" << cSquare9 << std::endl;
char cPlayerMark;
if (iPlayerTurn == 1) {
cPlayerMark = 'X';
} else {
cPlayerMark = 'O';
}
std::cout << "Player" << iPlayerTurn << "'s move:" << std::endl;
bool bValidMove;
// Loop until we get a valid move
do {
char cNextMove;
std::cin >> cNextMove;
bValidMove = true;
// Check for a valid move
if (cNextMove == '1' && cSquare1 == '1') {
cSquare1 = cPlayerMark;
} else if (cNextMove == '2' && cSquare2 == '2') {
cSquare2 = cPlayerMark;
} else if (cNextMove == '3' && cSquare3 == '3') {
cSquare3 = cPlayerMark;
} else if (cNextMove == '4' && cSquare4 == '4') {
cSquare4 = cPlayerMark;
} else if (cNextMove == '5' && cSquare5 == '5') {
cSquare5 = cPlayerMark;
} else if (cNextMove == '6' && cSquare6 == '6') {
cSquare6 = cPlayerMark;
} else if (cNextMove == '7' && cSquare7 == '7') {
cSquare7 = cPlayerMark;
} else if (cNextMove == '8' && cSquare8 == '8') {
cSquare8 = cPlayerMark;
} else if (cNextMove == '9' && cSquare9 == '9') {
cSquare9 = cPlayerMark;
} else {
std::cout << "Invalid Move. Try again." << std::endl;
bValidMove = false;
}
} while (!bValidMove);
bGameOver = false;
bool bWinGame = true;
if (cSquare1 != '1') {
if (cSquare2 == cSquare1 && cSquare3 == cSquare1) {
bGameOver = true;
}
if (cSquare4 == cSquare1 && cSquare7 == cSquare1) {
bGameOver = true;
}
}
if (cSquare5 != '5') {
if (cSquare1 == cSquare5 && cSquare9 == cSquare5) {
bGameOver = true;
}
if (cSquare2 == cSquare5 && cSquare8 == cSquare5) {
bGameOver = true;
}
if (cSquare4 == cSquare5 && cSquare6 == cSquare5) {
bGameOver = true;
}
if (cSquare3 == cSquare5 && cSquare7 == cSquare5) {
bGameOver = true;
}
}
if (cSquare9 != '9') {
if (cSquare3 == cSquare9 && cSquare6 == cSquare9) {
bGameOver = true;
}
if (cSquare7 == cSquare9 && cSquare8 == cSquare9) {
bGameOver = true;
}
}
if (cSquare1 != '1' && cSquare2 != '2' && cSquare3 != '3' &&
cSquare4 != '4' && cSquare5 != '5' && cSquare6 != '6' &&
cSquare7 != '7' && cSquare8 != '8' && cSquare9 != '9' && !bGameOver)
{
bGameOver = true;
bWinGame = false;
}
if (bGameOver) {
if (bWinGame) {
std::cout << "Player" << iPlayerTurn << " wins!" << std::endl;
}
// Print ending board
std::cout << cSquare1 << "|" << cSquare2 << "|" << cSquare3 << std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << cSquare4 << "|" << cSquare5 << "|" << cSquare6 << std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << cSquare7 << "|" << cSquare8 << "|" << cSquare9 << std::endl;
std::cout << "Game Over!" << std::endl;
std::cout << "Play again (y/n)?" << std::endl;
char cPlayAgain;
std::cin >> cPlayAgain;
if (cPlayAgain == 'y') {
bGameOver = false;
// Clear the board
cSquare1 = '1';
cSquare2 = '2';
cSquare3 = '3';
cSquare4 = '4';
cSquare5 = '5';
cSquare6 = '6';
cSquare7 = '7';
cSquare8 = '8';
cSquare9 = '9';
}
iPlayerTurn = 1;
} else {
// Alternate player turns
if (iPlayerTurn == 1) {
iPlayerTurn = 2;
} else {
iPlayerTurn = 1;
}
}
} while (!bGameOver);
}
the problem is the #include<stdlib> <---
I dunno what to do pls give a advice
Apr 7, 2012 at 12:59pm UTC
You have #include <stdib.h>
instead of #include <stdlib.h>
. It seems to need using namespace std;
also, since you're not putting std: in front of cout, cin etc. One last problem. What game is this supposed to play? The beginning says, cout<<"\t\t\tLet's Play Rock,Scissors,Paper!\t\n\n" ;
but, it plays Tic-Tac-Toe.
EDIT: Almost forgot about this small error in the program. int iPlayerTurn(1);
should be int iPlayerTurn = 1;
Last edited on Apr 7, 2012 at 1:07pm UTC
Apr 7, 2012 at 3:20pm UTC
Actually, since it's C++ code, it should probably be
#include <cstdlib>
(and yes, using namespace std;
, or the std:: in front of cout , cin , etc. does seem to be missing)
And int iPlayerTurn(1);
actually is valid.
It's like saying std::string str("Hello" );
.
Oh, and int main()
, not void main()
.
Apr 7, 2012 at 3:27pm UTC
@long double main
Thanks on the info about iPlayerTurn(1);
being valid coding. I do learn a lot of different programming styles being on this site