Sudoku Problems in C++

Discussion in 'C++' started by Xodiox, Jun 19, 2006.

  1. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Hi everyone. :)

    I have just started with programming in C++ a few weeks ago so I have not that much understanding of it. I have been given a project of making a Sudoku game,

    I have got my code to randomly choose a number and check it against the other numbers in the same row and column but i can't get it to check against the other numbers in the subgrid.

    Heres the main part of my code
    Code:
    int bad;
    int x;
    int i1;
    int j1;
    int i;
    int j;
    int n [ROWS][COLS];
    
    	for (i = 0; i < ROWS; i++) {
    		for (j = 0; j < COLS; j++) {
    
    		do { x = rand()%9 +1; bad = 0;   // random number
    		
                    for (i1 = 0; i1 < i; i1++)           // Checking against other numbers in the row
    			if (x == n[i1][j]) bad = 1;
    
    		for (j1 = 0; j1 < j; j1++)       // Checking against other numbers in the column
    		        if (x == n[i][j1]) bad = 1;
    				}while (bad);
    		n[i][j] = x; }
    	}
    
    	cout << "Sukodu Board:\n";
    	for (i = 0; i < ROWS; i++) {
    		for (j = 0; j < COLS; j++)
    			cout << n[i][j] << " ";  // Prints out the numbers
    
    I hope that you can follow the code.

    Thanks
     
    saiprem likes this.
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    See if [thread=541]Sudoku Solving Program Using 'C'[/thread] may help you.
     
  3. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    I read that artical very carefully before making this thread, but I it is a good start none the less.
     
  4. Xodiox

    Xodiox New Member

    Joined:
    Jun 19, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    I have been testing different sizes of boards and the biggest it can do is a 6 * 6 because any bigger and it does not display anything. I think that this is because it just takes too long to calculate which numbers can go to the different spaces.

    Any ideas on how I can make it calculate faster so I can get a 9 * 9 board ?

    Thanks for you help.
     
  5. saiprem

    saiprem New Member

    Joined:
    Jul 13, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Excuse me, can i view the source code of your program?i mean the total code
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice