Thread: Program isnt entering the If statements.

  1. #16
    Registered User
    Join Date
    Aug 2011
    Posts
    8

    The if statements arent working

    So I made a checking function named check();
    And well, the "test diagonals" is working but the "test rows" isnt working.
    And when I exchange their positions, "test rows" will be the one working while "test diagonals isn't working.

    Whats the problem with this?

    Code:
    /* See if there is a winner. */
    char check()
    {
      int i;
     /* test diagonals */
      if(board[0][0]==board[1][1] && board[1][1]==board[2][2]) 
      return board[0][0];
    
      if(board[0][2]==board[1][1] && board[1][1]==board[2][0])
           return board[0][2];
           
      if(board[0][6]==board[1][7] && board[1][7]==board[2][8])
         return board[0][6];
         
      if(board[0][8]==board[1][7] && board[1][7]==board[2][6])
         return board[0][8];    
    
      /* test row*/  
      for(i=0; i<3; i++)
      {
      
        if(board[i][0]==board[i][1] && board[i][0]==board[i][2]) 
        return board[i][0];
        
        if(board[i][3]==board[i][4] && board[i][3]==board[i][5])
        return board[i][3];
        
        if(board[i][6]==board[i][7] && board[i][6]==board[i][8])
        return board[i][6];
      }
      
     
     }

  2. #17
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Well for starters, your function can reach the end without returning. Currently it will check who won, but will only work if somebody did.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #18
    Registered User
    Join Date
    Aug 2011
    Posts
    8
    Quote Originally Posted by King Mir View Post
    Well for starters, your function can reach the end without returning. Currently it will check who won, but will only work if somebody did.
    The function isn't complete, I;ve just been testing the diagonals and rows. I tested it, and diagonal wining combination is working but the row winning combinations isnt working. I added:
    Code:
    return ' ';
    if that helps, but its still isn't working.

    Sorry I dont get what you meant.
    and the function isnt working well.
    Last edited by ceptyoubestbud; 08-14-2011 at 02:49 AM.

  4. #19
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,334
    Describe in what way the function isn't working. Isn't finding winning rows when it should? Finding winning rows when it shouldn't? Returning the wrong person? What?

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Providing an incomplete function and saying it "isn't working" doesn't cut it.

    People here are not mind readers. Since you haven't given any useful information, we don't know why you wrote the function, what you have left out, what data you have supplied to it, what you expect it to do, or what it actually does. All of those things we don't know make it sort of difficult to give a useful answer.

    There is a skill in asking a question in a manner that elicits a useful response. You need to develop such a skill.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #21
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    @OP:
    If this is the same "flip tic-tac-toe" homework assignment that has been posted here between 1 and 2 weeks ago then I have the following suggestions for you:

    1. Go back through your class notes and book to review the material provided.
    2. Actually look at the problem statement and code provided by your professor and think about what is happening.
    3. Sit down and work out the problem on paper. Just because you were provided with code doesn't mean the first step is to start programming.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 09-23-2010, 04:15 AM
  2. printf statements effecting program
    By Brain_Child in forum C Programming
    Replies: 3
    Last Post: 11-06-2009, 10:57 AM
  3. Program for entering the Ordinal of a Number
    By jugs in forum C Programming
    Replies: 1
    Last Post: 10-13-2009, 03:47 AM
  4. Program Issue, if and else if statements
    By kordric in forum C++ Programming
    Replies: 2
    Last Post: 03-29-2008, 05:46 PM
  5. Simple C Program with Flow Statements
    By rory-uk in forum C Programming
    Replies: 16
    Last Post: 02-06-2008, 01:12 PM