Ignoring my input (as a bad thing)

This is a discussion on Ignoring my input (as a bad thing) within the C++ Programming forums, part of the General Programming Boards category; This is part of an incomplete tic-tac-toe program. Whenever I FIRST input my move, insted of clearing the screen, it ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917

    Ignoring my input (as a bad thing)

    This is part of an incomplete tic-tac-toe program. Whenever I FIRST input my move, insted of clearing the screen, it just moves the cursu down and ignores what I put it. But when I put it in again, the program never does that again. I will attach the exe.

    PHP Code:
    array turn()
    {
        array 
    result = new float[2];
        
    char UserInput[4];
        
    cout<<""<<endl
            
    <<"\t\t                   Tic-Tack-Toe"<<endl
            
    <<""<<endl
            
    <<"\t\t       1                 2                3"<<endl
            
    <<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t1\t        "<<board.sec1_1<<"       "<<(char)176<<"        "<<board.sec1_2<<"       "<<(char)176<<"        "<<board.sec1_3<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t"<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)176<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)176<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t2\t        "<<board.sec2_1<<"       "<<(char)176<<"        "<<board.sec2_2<<"       "<<(char)176<<"        "<<board.sec2_3<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t"<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)176<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)176<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<(char)220<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t3\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t        "<<board.sec3_1<<"       "<<(char)176<<"        "<<board.sec3_2<<"       "<<(char)176<<"        "<<board.sec3_3<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<"\t\t                "<<(char)176<<"                "<<(char)176<<""<<endl
            
    <<""<<names.currentplayer<<", please input coord you wish to move on."<<endl;
        
    cin.ignore(80,'\n');
        
    cin.getline(UserInput,4);
        
    system("cls");
        switch(
    UserInput[0])
        {
        case 
    '1':
            {
                
    result[0] = 1;
            }break;
        case 
    '2':
            {
                
    result[0] = 2;
            }break;
        case 
    '3':
            {
                
    result[0] = 3;
            }break;
        case 
    'e':
            {
                
    result[0] = 9;
            }break;
        default:
            {
                
    system("cls");
                
    turn();
                break;
            }break;
        }
        switch(
    UserInput[2])
        {
        case 
    '1':
            {
                
    result[1] = 1;
            }break;
        case 
    '2':
            {
                
    result[1] = 2;
            }break;
        case 
    '3':
            {
                
    result[1] = 3;
            }break;
        default:
            {
                
    system("cls");
                
    turn();
                break;
            }break;
        }
        return 
    result;

    Attached Files Attached Files
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    try putting cin.ignore(); function after the getline
    Last edited by neandrake; 03-10-2002 at 03:36 PM.
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  3. #3
    Unregistered
    Guest
    what does the following line mean?

    array result = new float[2];

    is array typedefed as float * or something?

    in your program, what comes before the first call to turn()?

  4. #4
    Registered User
    Join Date
    Mar 2002
    Location
    South Africa
    Posts
    35

    Another thing

    Your game also never ends . It doesn't check for the winning condition (three noughts or three crosses in a row), and it doesn't check to see if the board is full.
    I code.
    I think.
    Ergo, I think in code.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    917
    I said INCOMPLETE, you moron. I've completed it now, anyway.



    Thanks for the help, Neandrake; worked.

    The program and code are attached.
    Attached Files Attached Files
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 04:25 PM
  2. Input class project (again)
    By Elysia in forum C++ Programming
    Replies: 41
    Last Post: 02-13-2009, 10:52 AM
  3. h/w help
    By helpme in forum C Programming
    Replies: 20
    Last Post: 10-21-2003, 10:36 AM
  4. Catching bad input
    By Asmodan in forum C++ Programming
    Replies: 3
    Last Post: 05-28-2002, 07:24 PM

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