Thread: Problems on creating a sudoku verifier

  1. #16
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by twoxacross View Post
    last question:
    How can I add a whole row,column or box?(Should I do if(a[0]+a[1]+...+a[8] = 45)
    printf(...

    or is there a shorter way to do it?

    And how can I make the program verify if a number is not repeated in a row,column,and a box?
    That my friend is why the C Gods gave us loops....

  2. #17
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by twoxacross View Post
    I know how sudoku works.
    It's just an example ,and I know that example is gonna make the program display that it's not a valid board.
    I was talking about the sum of each row,column,and board.

    Thanks for the replies.
    Sorry if I don't know much about programming yet.
    Quote Originally Posted by AndrewHunter View Post
    You will need to sum the elements of the array up yourself using a loop. You should read: Lesson 3 - Loops and Lesson 8 -Arrays. These lessons will show you what you need to do.
    Quote Originally Posted by twoxacross View Post
    last question:
    How can I add a whole row,column or box?(Should I do if(a[0]+a[1]+...+a[8] = 45)
    printf(...

    or is there a shorter way to do it?

    And how can I make the program verify if a number is not repeated in a row,column,and a box?
    Quote Originally Posted by Salem View Post
    Use some for() loops.
    Hmm...looks like I could have used a loop for the replies.
    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.

  3. #18
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Hmm...looks like I could have used a loop for the replies.
    You know buddy ain't reading text... merely trying to scoop and poop code samples when he asks a question AFTER you answer it!

    At that point, any further attempts to educate or direct would be better focused upon that huge rock in your neighbor's back yard...

  4. #19
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Quote Originally Posted by CommonTater View Post
    ....At that point, any further attempts to educate or direct would be better focused upon that huge rock in your neighbor's back yard...
    LOL....true. At least I wouldn't have to worry about backtalk that way.
    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.

  5. #20
    Registered User
    Join Date
    Aug 2011
    Posts
    6
    I tried coding it.The only part left is verifying a 3x3 box and verifying if the digits are valid.I don't get errors when compiling,but when I run the executable file,after entering the digits,I receive an error report with the "send and don't send options".





    Code:
    #include<stdio.h>
    #include<string.h>
    
    int main() {
    
        char input[81];
        int board[9][9];
        int row;
        int col;
        int x,y;
        
        printf("Enter 81 consecutive digits for a sudoku board: ");
        scanf("%s", &input);
       
       
        void displayValid() {
             printf("Valid sudoku board");
    }     
       
          for(col = 0; col < 9; col++) 
            if(col != x && board[x][col] == board[x][y]) 
                   printf("Not a valid sudoku board");
     
     
          for(row = 0; row < 9; row++) 
            if(row != x && board[row][y] == board[x][y]) 
                   printf("Not a valid sudoku board");    
     
          
          for(x = 0;x < 9; x++) 
            for(y = 0;y < 9;y++) 
              if(board[x][y] != 0) 
                printf("Not a valid sudoku board");
          
    
          for(x = 0;x < 9;x++) 
             for(y = 0;y < 9;y++) 
              if((board[x][y] < 0) || (board[x][y] > 9)) 
                 printf("Not a valid sudoku board");
      
          
          for(x = 0;x < 9;x++) 
           for(y = 0;y < 9;y++) 
            if(board[x][y] != 0) 
              printf("Not a valid sudoku board"); 
          
          else {
           displayValid();
    }                  
            
                   
        getche();
        return 0;
    }

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > char input[81];
    To store 81 characters, you need to allocate 82 chars - remember all strings have a \0 at the end.

    > int board[9][9];
    The next thing you need to do is copy the characters to the board (as integers), before you start validating it.
    So for example,
    board[0][0] = input[0] - '0';
    board[0][1] = input[1] - '0';

    Use some for loops to achieve this.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #22
    Registered User
    Join Date
    Aug 2011
    Posts
    6
    Thanks.

    I forgot that it starts from [0] not [1].

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems creating new line
    By cjohnson412 in forum C++ Programming
    Replies: 4
    Last Post: 02-03-2008, 11:31 PM
  2. having problems with creating a file
    By jackmanplus in forum C++ Programming
    Replies: 6
    Last Post: 07-24-2006, 08:47 PM
  3. Problems creating a new class
    By nickname_changed in forum C++ Programming
    Replies: 3
    Last Post: 05-22-2003, 01:47 AM
  4. Equation Verifier! Almost complete!
    By Nakeerb in forum C++ Programming
    Replies: 5
    Last Post: 11-30-2002, 02:26 PM
  5. Idea: Formula Verifier
    By vasanth in forum Contests Board
    Replies: 2
    Last Post: 10-08-2002, 06:43 AM