Thread: Vector subscript out of range? (Sudoku)

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    Quote Originally Posted by matsp View Post
    Can you describe what it is that you are trying to tackle?

    --
    Mats

    1. The void displayboard function, "You could just put them into your vector before you show the board the first time. " I don't know what you mean by this.

    2. I'm still trying to get my program to recognise each cell location so that when the user inputs 1-9 it will be put in to that cell, but before doing that i need enter the constants ike you said earlier, however the way i'm doing it would take forever.
    Last edited by mt1; 03-03-2009 at 07:26 AM.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, how much do you understand about manipulating vectors in general - how would you put the number 6 in cell number 7 of a vector? Now, if you know that, how would you fill in the constant part of the Sudoku puzzle?

    Also, what sort of input have you dealt with so far?

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    Quote Originally Posted by matsp View Post
    So, how much do you understand about manipulating vectors in general - how would you put the number 6 in cell number 7 of a vector? Now, if you know that, how would you fill in the constant part of the Sudoku puzzle?

    Also, what sort of input have you dealt with so far?

    --
    Mats
    Never dealt with vectors before, was just an idea I cam across whilst reading my book, thought I could adapt from the Tic Tac Toe program from the book. I tried to adapt from it but it's proving a bit complicated...

    Code:
    void instructions()
    {
        cout << "Welcome to the ultimate man-machine showdown: Tic-Tac-Toe.\n";
        cout << "--where human brain is pit against silicon processor\n\n";
    
        cout << "Make your move known by entering a number, 0 - 8.  The number\n";
        cout << "corresponds to the desired board position, as illustrated:\n\n";
        
        cout << "       0 | 1 | 2\n";
        cout << "       ---------\n";
        cout << "       3 | 4 | 5\n";
        cout << "       ---------\n";
        cout << "       6 | 7 | 8\n\n";
    
        cout << "Prepare yourself, human.  The battle is about to begin.\n\n";
    }
    about input, the only input i've done is something like this

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {	
    	//	Declarations
    	double celsius, fahrenheit;
    
    	//	Input
    	cout << "Enter temperature in Celsius: ";
    	cin >> celsius;
    	cout << endl;
    
    	//	Calculation
    	fahrenheit = (celsius*9)/5 +32;
    
    	//	Output
    	cout << celsius << " Celsius is (approx.) ";
    	cout << fahrenheit  << "F.";
    	cout << endl << endl;
    
    	return 0;
    }

  4. #19
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    So, given what you know of the vectors and cin >>.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #20
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    Quote Originally Posted by matsp View Post
    So, how much do you understand about manipulating vectors in general - how would you put the number 6 in cell number 7 of a vector? Now, if you know that, how would you fill in the constant part of the Sudoku puzzle?

    Also, what sort of input have you dealt with so far?

    --
    Mats
    cout << " " << board[7];

    cin >> board[7];

    *shrugs*

  6. #21
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by mt1 View Post
    cout << " " << board[7];

    cin >> board[7];

    *shrugs*
    Right, I think you need to learn a bit more about vectors and input/output (I/O) before you try to write a rather complex program.

    I'm sorry, but holding your hand through this is probably a bit too much for me to cope with. Try looking at the tutorials on www.cprogramming.com - I'm pretty sure there is a section on vectors. And another on covers simple input & output.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #22
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    Quote Originally Posted by matsp View Post
    Right, I think you need to learn a bit more about vectors and input/output (I/O) before you try to write a rather complex program.

    I'm sorry, but holding your hand through this is probably a bit too much for me to cope with. Try looking at the tutorials on www.cprogramming.com - I'm pretty sure there is a section on vectors. And another on covers simple input & output.

    --
    Mats
    Ok.

    I can see file I/O but that's probably not what i'm looking for? Can't see anything about vectors.

  8. #23
    Registered User
    Join Date
    Feb 2009
    Posts
    42
    Quote Originally Posted by mt1 View Post
    Ok.

    I can see file I/O but that's probably not what i'm looking for? Can't see anything about vectors.
    http://www.cprogramming.com/tutorial/stl/vector.html

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Overflow and range checking for mul/div
    By Elysia in forum C++ Programming
    Replies: 28
    Last Post: 06-06-2008, 02:09 PM
  2. Help for a sudoku Solver
    By axilleask in forum C Programming
    Replies: 3
    Last Post: 11-26-2007, 03:28 PM
  3. Srand () w/ range
    By xsbinary in forum C Programming
    Replies: 9
    Last Post: 10-21-2007, 03:24 PM
  4. Please help to check.
    By nicoleha in forum C Programming
    Replies: 16
    Last Post: 12-07-2005, 02:29 PM
  5. Sudoku - the new addiction
    By axon in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 11-07-2005, 10:39 PM