Like Tree2Likes
  • 2 Post By Neo1

(noob) help with tictactoe program

This is a discussion on (noob) help with tictactoe program within the C++ Programming forums, part of the General Programming Boards category; I just started learning c++ and i wanted to created a 2 players tictactoe game. Even if the program isn't ...

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    1

    (noob) help with tictactoe program

    I just started learning c++ and i wanted to created a 2 players tictactoe game. Even if the program isn't complete i have an idea of how to write in grids and how to check winners(i check for 3 same input in a horizontal, vertical or oblique line). What i can't get is how to get error if i write on a grid where i already gave an input. Also i would like to put the input lines in separate functions.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main (){
    int x;
    int y;
    string gr1="1";
    string gr2="2";
    string gr3="3";
    string gr4="4";
    string gr5="5";
    string gr6="6";
    string gr7="7";
    string gr8="8";
    string gr9="9";
    cout << gr1 << "|" << gr2 << "|" << gr3 << "\n" << gr4 << "|" << gr5 << "|" << gr6 << "\n" << gr7 << "|" << gr8 << "|" << gr9 << endl;
    cout << "player 1 you are X, select" << endl;
    gr1=" ";
    gr2=" ";
    gr3=" ";
    gr4=" ";
    gr5=" ";
    gr6=" ";
    gr7=" ";
    gr8=" ";
    gr9=" ";
    cin >> x;
    switch(x){
    case 1: gr1="X";
    break;
    case 2: gr2="X";
    break;
    case 3: gr3="X";
    break;
    case 4: gr4="X";
    break;
    case 5: gr5="X";
    break;
    case 6: gr6="X";
    break;
    case 7: gr7="X";
    break;
    case 8: gr8="X";
    break;
    case 9: gr9="X";
    break;
    }
    cout << gr1 << "|" << gr2 << "|" << gr3 << "\n" << gr4 << "|" << gr5 << "|" << gr6 << "\n" << gr7 << "|" << gr8 << "|" << gr9 << endl;
    cout << "payer 2 you are O, select" << endl;
    cin >> y;
    
    switch(y){
    case 1: gr1="O";
    break;
    case 2: gr2="O";
    break;
    case 3: gr3="O";
    break;
    case 4: gr4="O";
    break;
    case 5: gr5="O";
    break;
    case 6: gr6="O";
    break;
    case 7: gr7="O";
    break;
    case 8: gr8="O";
    break;
    case 9: gr9="O";
    break;
    }
    cout << gr1 << "|" << gr2 << "|" << gr3 << "\n" << gr4 << "|" << gr5 << "|" << gr6 << "\n" << gr7 << "|" << gr8 << "|" << gr9 << endl;
    }
    thanks in advance

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    You're not ready to write a tic-tac-toe game yet. You need to learn about arrays and loops first.
    iMalc and workisnotfun like this.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Noob - Program Keeps Crashing
    By icu222much in forum C++ Programming
    Replies: 7
    Last Post: 09-20-2009, 11:34 AM
  2. noob help on simple program
    By halfpint101 in forum C++ Programming
    Replies: 3
    Last Post: 12-18-2007, 07:29 PM
  3. ticTacToe program, logic help!
    By gomantis in forum C Programming
    Replies: 1
    Last Post: 10-14-2007, 09:52 PM
  4. tictactoe program
    By ademkiv in forum C Programming
    Replies: 4
    Last Post: 03-16-2006, 08:38 PM
  5. another noob program
    By rodrigorules in forum C++ Programming
    Replies: 6
    Last Post: 11-26-2005, 11:22 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21