What's the prolem in my code:
ThanksCode:#include <iostream.h> #include <stdlib.h> #include <windows.h> int Tic[3][3]; void ClearBoard(void) { Tic[0][0] = 0; Tic[0][1] = 0; Tic[0][2] = 0; Tic[1][0] = 0; Tic[1][1] = 0; Tic[1][2] = 0; Tic[2][0] = 0; Tic[2][1] = 0; Tic[2][2] = 0; } void ShowBoard(void) { cout << Tic[0][0] << Tic[0][1] << Tic[0][2] << endl; cout << Tic[1][0] << Tic[1][1] << Tic[1][2] << endl; cout << Tic[2][0] << Tic[2][1] << Tic[2][2] << "\n\n\n"; } void StartGame(void) { char name1[50]; char name2[50]; cout << "\n\nStarting A New Game!" << endl; cout << "Player1, please input your name: "; cin >> name1; cout << "Player2, please input your name: "; cin >> name2; cout << "\nStarting battle: " << name1 << " vs. " << name2 << endl; ClearBoard(); ShowBoard(); int i; i = 0; int col; int row; do { cout << "Turn: " << name1 << endl; cout << name1 << ", please input your move: "; cin >> col; cin >> row; Tic[col-1][row-1] = 1 ShowBoard(); cout << "Turn: " << name2 << endl; cout << name2 << ", please input your move: "; cin >> col; cin >> row; Tic[col-1][row-1] = 1 ShowBoard(); }while(x != 0); } int main() { cout << "Welcome To Tic Tac Toe !" << endl; cout << "Menu:\n\n"; cout << "1. Start New Tic Tac Toe Game" << endl; cout << "2. Exit Tic Tac Toe" << endl << endl; cout << "Your choice: "; int choice; cin << choice; switch(choice) { case 1: StartGame(); break; case 2: cout << "Thanks For Playing Tic Tac Toe!" << endl; cout << "Programmed By Dark-Dragon (ruski2003@hotmail.com)" << endl; system("pause"); return 0; break; default: cout << "Error Input! Quitting..."; system("cls"); system("pause"); return 0; } }![]()



LinkBack URL
About LinkBacks
:




Your code works fine except for that "cin << choice;" part. It's amazing how one stupid line can mess up a finely written code...
that's no fun ... But I asked some people on IRC and they told me that I'll get used to that just like they did, so i think I'll be fine. 