i'm currently doing an assignment which asked me to do something like a sudoku. but this 1 is a 4 by 4 sudoku.
the part tat i'm stuck is where i need to make a grid tat enable the user to move around in it n input their answers.

Make an Id grid like so :

_______________________________
|  a    |   b     |    c   |    d      |
--------------------------------
|   e   |     f   |     g  |     h     |
--------------------------------
|   i   |     j   |   k    |    L    |
--------------------------------
|    m  |       n |    o   |    p      |
--------------------------------

i think i done tat. the thing is i have no idea how to let the user to move in the grid n input + erase as the user please.

below is my code.

#include <iostream>
using namespace std;

void displayMenu()
{
	system("cls");
	cout << "+-------------------------------------+" << endl;
	cout << "| TetraPek Inc. |" << endl;
	cout << "|=====================================|" << endl;
	cout << "| Select: |" << endl;
	cout << "| 1 => Display Rules |" << endl;
	cout << "| 2 => Start Playing |" << endl;
	cout << "|-------------------------------------|" << endl;
	cout << "|-------------------------------------|" << endl;
	cout << "| Q => Quit |" << endl;
	cout << "+-------------------------------------+" << endl;
	cout << endl;
	cout << "Choice => ";
}
void displayRules ()
{
	cout << "Make your move known by entering a number from 1 to 4" << endl;
    cout << "Below indicate the position the number you insert" << endl;  
    cout << "+---------------------------+" << endl;
    cout << "   r1c1   r1c2 | r1c3   r1c4|\n";
    cout << "   r2c1   r2c2 | r2c3   r2c4|\n";
    cout << " ---------------------------------\n";
    cout << "   r3c1   r3c2 | r3c3   r3c4|\n";
    cout << "   r4c1   r4c2 | r4c3   r4c4|\n";
    cout << "+---------------------------+" << endl;
    cout << "Enter values by row, from left to right, and press the 'ENTER' key" << endl;
}
void printGrid()
{
	int r1c1 = 0,r1c2 = 0,r1c3 = 0,r1c4 = 0;
	int r2c1 = 0,r2c2 = 0,r2c3 = 0,r2c4 = 0;
	int r3c1 = 0,r3c2 = 0,r3c3 = 0,r3c4 = 0;
	int r4c1 = 0,r4c2 = 0,r4c3 = 0,r4c4 = 0;
	int col1 =r1c1;
	int col2 =r1c2;
	int col3 =r1c3;
	int col4 =r1c4;
	int line =0;
	while(line <=4)
	{
		switch(line)
		{
			case 0:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << col1 << "\t|";
 				cout << "\t" << col2 << "\t|";
 				cout << "\t" << col3 << "\t|";
 				cout << "\t" << col4 << "\t|\n";
				line++;
 			case 1:
				col1 =r2c1;
				col2 =r2c2;
				col3 =r2c3;
				col4 =r2c4;
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << col1 << "\t|";
 				cout << "\t" << col2 << "\t|";
 				cout << "\t" << col3 << "\t|";
 				cout << "\t" << col4 << "\t|\n";
				line++;
 			case 2:
				col1 =r3c1;
				col2 =r3c2;
				col3 =r3c3;
				col4 =r3c4;
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << col1 << "\t|";
 				cout << "\t" << col2 << "\t|";
 				cout << "\t" << col3 << "\t|";
 				cout << "\t" << col4 << "\t|\n";
				line++;
 			case 3:
				col1 =r4c1;
				col2 =r4c2;
				col3 =r4c3;
				col4 =r4c4;
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << col1 << "\t|";
 				cout << "\t" << col2 << "\t|";
 				cout << "\t" << col3 << "\t|";
 				cout << "\t" << col4 << "\t|\n";
 				line++;
 			case 4:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << endl;
				line++;
	
		}
	}
}
int main()
{

	bool done = false;
	do
	{
		displayMenu();
		cin >> choice;
	choice = toupper(choice);
	switch (choice)
		{
			case '1' : displayRules();
			system("pause");
			break;
			case '2' : printGrid();
			system("pause");
			break;
			case 'Q' : done = true;
			break;
			default : cout << "Invalid selection, try again!" << endl;
			system("pause");
			break;
		}
	} 
	while (!done);
	cout << "Good Bye!" << endl;
	cout << endl;
}

the program needs remember only the current pos and the position that contains mouse clicked pointer pos and do smt if it is in the current pos' neighbor.

I'm sorry I am still not getting your problem

Please, post code in code tags and don't put as title things like: URGENT!!!, HELP!!!!!!, ERROR!!!!, Your Title Here...

Thanks!

firstPerson:
my question is...how to move in a grid so tat u can input + erase the asnwer...?

ebookfinder:
erm...confused. mind to explain it in more detail??

Nathan:
sorry. didnt read the rules n stuff and juz rush in to ask questions.
i wont repeat it again.

Yes, please read the rules regarding code tags and chat-speak as well as this thread:

http://catb.org/esr/faqs/smart-questions.html

Here's your code:

#include <iostream>
using namespace std;

void displayMenu()
{
    system("cls");
    cout << "+-------------------------------------+" << endl;
    cout << "| TetraPek Inc. |" << endl;
    cout << "|=====================================|" << endl;
    cout << "| Select: |" << endl;
    cout << "| 1 => Display Rules |" << endl;
    cout << "| 2 => Start Playing |" << endl;
    cout << "|-------------------------------------|" << endl;
    cout << "|-------------------------------------|" << endl;
    cout << "| Q => Quit |" << endl;
    cout << "+-------------------------------------+" << endl;
    cout << endl;
    cout << "Choice => ";
}
void displayRules ()
{
    cout << "Make your move known by entering a number from 1 to 4" << endl;
    cout << "Below indicate the position the number you insert" << endl;  
    cout << "+---------------------------+" << endl;
    cout << "   r1c1   r1c2 | r1c3   r1c4|\n";
    cout << "   r2c1   r2c2 | r2c3   r2c4|\n";
    cout << " ---------------------------------\n";
    cout << "   r3c1   r3c2 | r3c3   r3c4|\n";
    cout << "   r4c1   r4c2 | r4c3   r4c4|\n";
    cout << "+---------------------------+" << endl;
    cout << "Enter values by row, from left to right, and press the 'ENTER' key" << endl;
}
void printGrid()
{
    int r1c1 = 0,r1c2 = 0,r1c3 = 0,r1c4 = 0;
    int r2c1 = 0,r2c2 = 0,r2c3 = 0,r2c4 = 0;
    int r3c1 = 0,r3c2 = 0,r3c3 = 0,r3c4 = 0;
    int r4c1 = 0,r4c2 = 0,r4c3 = 0,r4c4 = 0;
    int col1 =r1c1;
    int col2 =r1c2;
    int col3 =r1c3;
    int col4 =r1c4;
    int line =0;
    while(line <=4)
    {
        switch(line)
        {
            case 0:
            for (int plus = 0 ; plus <= 65 ; plus++)
            {
                cout << "+";
            }
                cout << "\n|\t" << col1 << "\t|";
                cout << "\t" << col2 << "\t|";
                cout << "\t" << col3 << "\t|";
                cout << "\t" << col4 << "\t|\n";
                line++;
            case 1:
                col1 =r2c1;
                col2 =r2c2;
                col3 =r2c3;
                col4 =r2c4;
            for (int plus = 0 ; plus <= 65 ; plus++)
            {
                cout << "+";
            }
                cout << "\n|\t" << col1 << "\t|";
                cout << "\t" << col2 << "\t|";
                cout << "\t" << col3 << "\t|";
                cout << "\t" << col4 << "\t|\n";
                line++;
            case 2:
                col1 =r3c1;
                col2 =r3c2;
                col3 =r3c3;
                col4 =r3c4;
            for (int plus = 0 ; plus <= 65 ; plus++)
            {
                cout << "+";
            }
                cout << "\n|\t" << col1 << "\t|";
                cout << "\t" << col2 << "\t|";
                cout << "\t" << col3 << "\t|";
                cout << "\t" << col4 << "\t|\n";
                line++;
            case 3:
                col1 =r4c1;
                col2 =r4c2;
                col3 =r4c3;
                col4 =r4c4;
            for (int plus = 0 ; plus <= 65 ; plus++)
            {
                cout << "+";
            }
                cout << "\n|\t" << col1 << "\t|";
                cout << "\t" << col2 << "\t|";
                cout << "\t" << col3 << "\t|";
                cout << "\t" << col4 << "\t|\n";
                line++;
            case 4:
            for (int plus = 0 ; plus <= 65 ; plus++)
            {
                cout << "+";
            }
                cout << endl;
                line++;

        }
    }
}
int main()
{

    bool done = false;
    do
    {
        displayMenu();
        cin >> choice;
    choice = toupper(choice);
    switch (choice)
        {
            case '1' : displayRules();
            system("pause");
            break;
            case '2' : printGrid();
            system("pause");
            break;
            case 'Q' : done = true;
            break;
            default : cout << "Invalid selection, try again!" << endl;
            system("pause");
            break;
        }
    } 
    while (!done);
    cout << "Good Bye!" << endl;
    cout << endl;
}

How do you move in a grid? As in, how do you press the arrow keys so your cursor is in a certain box? I think you'll have to use something like ncurses.

http://en.wikipedia.org/wiki/Ncurses

But here it seems that you DON'T want to do that. You just want the user to type in the row and column. Please elaborate.

void displayRules ()
{
    cout << "Make your move known by entering a number from 1 to 4" << endl;
    cout << "Below indicate the position the number you insert" << endl;  
    cout << "+---------------------------+" << endl;
    cout << "   r1c1   r1c2 | r1c3   r1c4|\n";
    cout << "   r2c1   r2c2 | r2c3   r2c4|\n";
    cout << " ---------------------------------\n";
    cout << "   r3c1   r3c2 | r3c3   r3c4|\n";
    cout << "   r4c1   r4c2 | r4c3   r4c4|\n";
    cout << "+---------------------------+" << endl;
    cout << "Enter values by row, from left to right, and press the 'ENTER' key" << endl;
}

It's ok Sieghuirt!
Follow the tips of VernonDozier!

VernonDozier:
the ncurses is a library tat i need to dl from the net??
asking my lec whether this is ok. since he didnt teach us anything bout this.
so, is there any alternative way??
one more question.
in the grid i made, it display 0.
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
now i have to put in 8 randomize number in it. so tat the user need to input another 8.
| 1 | | 3| | | | |
| 2 | | 4 | | | | |
| | | | | 1 | | 2 |
| | | | | 4 | | 3 |

wat i did is....i fix the position for the number to randomize but it end up ignoring the sudoku rules.
| 1 | | 2| | | | |
| 2 | | 4 | | | | |
| | | | | 4 | | 2 |
| | | | | 4 | | 3 |
how to solve this??
and if i wanted to make the randomize position to b randomize too, how to do tat??

VernonDozier:
the ncurses is a library tat i need to dl from the net??
asking my lec whether this is ok. since he didnt teach us anything bout this.
so, is there any alternative way??
one more question.
in the grid i made, it display 0.
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
now i have to put in 8 randomize number in it. so tat the user need to input another 8.
| 1 | | 3| | | | |
| 2 | | 4 | | | | |
| | | | | 1 | | 2 |
| | | | | 4 | | 3 |

wat i did is....i fix the position for the number to randomize but it end up ignoring the sudoku rules.
| 1 | | 2| | | | |
| 2 | | 4 | | | | |
| | | | | 4 | | 2 |
| | | | | 4 | | 3 |
how to solve this??
and if i wanted to make the randomize position to b randomize too, how to do tat??

I have no idea whether you want to use ncurses or not. I imagine you'd have to download it since I can't imagine that it's standard. I've never actually used it. But again, referring to my last post, it's not clear whether you are you are moving with the arrow keys or by typing in row and column. If you type in row and column and just keep reprinting the grid, there's no need for anything like ncurses.

i would like to use the ncurses but the thing is since it is new to me, it take time and the due date is kinda near for my assignment. i'm afraid tat i might not get it in time tat's y i'm asking for an alternative way to solve this.

how bout the randomize part i'm asking??

thanks a lot for helping.

.

i would like to use the ncurses but the thing is since it is new to me, it take time and the due date is kinda near for my assignment. i'm afraid tat i might not get it in time tat's y i'm asking for an alternative way to solve this.

how bout the randomize part i'm asking??

thanks a lot for helping.

Well, I already asked you twice in two previous posts to clarify what you are trying to do. As I mentioned previously, one way would require ncurses or something similar, one way doesn't, which is why I asked for clarification, which you haven't provided. I've never used ncurses. I don't know what the alternatives are. I don't know what operating system you have. I don't know whether you are allowed to use non-standard libraries. Your questions cannot be answered without you providing answers to these questions.

Ditto with "randomize". That could mean twenty different things. You're going to have to explain what you want. I assume you are familiar with the rand () and srand (unsigned int) functions.

i have done it by type in row and column and keep reprinting the grid.
so, let's forget my stupid attempt.

i'm not tat familiar with rand () and srand ().
but i do wrote a code for the randomization but there's some prob as i can't seem to make it follow the sudoku rules.

int r1c1,r1c2,r1c3,r1c4;
	int r2c1,r2c2,r2c3,r2c4;
	int r3c1,r3c2,r3c3,r3c4;
	int r4c1,r4c2,r4c3,r4c4;
	int a;

		if ( r1c2 == r1c1 || r1c2 == r1c3 || r1c2 == r1c4 || r1c2 == r2c1 || r1c2 == r2c2 || r1c2 == r3c2 || r1c2 == r4c2 )
		r1c2 = rand () % 4 + 1;
		if ( r1c3 == r1c1 || r1c3 == r1c2 || r1c3 == r1c4 || r1c3 == r2c3 || r1c3 == r2c4 || r1c3 == r3c3 || r1c3 == r4c3 )
		r1c3 = rand () % 4 + 1;
		if ( r1c4 == r1c1 || r1c4 == r1c2 || r1c4 == r1c3 || r1c4 == r2c3 || r1c4 == r2c4 || r1c4 == r3c4 || r1c4 == r4c4 )
		r1c4 = rand () % 4 + 1;
		if ( r2c1 == r2c2 || r2c1 == r2c3 || r2c1 == r2c4 || r2c1 == r1c1 || r2c1 == r1c2 || r2c1 == r3c1 || r2c1 == r4c1 )
		r2c1 = rand () % 4 + 1;
		if ( r2c2 == r2c1 || r2c2 == r2c3 || r2c2 == r2c4 || r2c2 == r1c1 || r2c2 == r1c2 || r2c2 == r3c2 || r2c2 == r4c2 )
		r2c2 = rand () % 4 + 1;
		if ( r2c3 == r2c1 || r2c3 == r2c2 || r2c3 == r2c4 || r2c3 == r1c3 || r2c3 == r1c4 || r2c3 == r3c3 || r2c3 == r4c3 )
		r2c3 = rand () % 4 + 1;
		if ( r2c4 == r2c1 || r2c4 == r2c2 || r2c4 == r2c3 || r2c4 == r1c3 || r2c4 == r1c4 || r2c4 == r3c4 || r2c4 == r4c4 )
		r2c4 = rand () % 4 + 1;
		if ( r3c1 == r3c2 || r3c1 == r3c3 || r3c1 == r3c4 || r3c1 == r4c1 || r3c1 == r4c2 || r3c1 == r2c1 || r3c1 == r1c1 )
		r3c1 = rand () % 4 + 1;
		if ( r3c2 == r3c1 || r3c2 == r3c3 || r3c2 == r3c4 || r3c2 == r4c1 || r3c2 == r4c2 || r3c2 == r2c2 || r3c2 == r1c2 )
		r3c2 = rand () % 4 + 1;
		if ( r3c3 == r3c1 || r3c3 == r3c2 || r3c3 == r3c4 || r3c3 == r4c3 || r3c3 == r4c4 || r3c3 == r2c3 || r3c3 == r1c3 )
		r3c3 = rand () % 4 + 1;
		if ( r3c4 == r3c1 || r3c4 == r3c2 || r3c4 == r3c3 || r3c4 == r4c3 || r3c4 == r4c4 || r3c4 == r2c4 || r3c4 == r1c4 )
		r3c4 = rand () % 4 + 1;
		if ( r4c1 == r4c2 || r4c1 == r4c3 || r4c1 == r4c4 || r4c1 == r3c1 || r4c1 == r3c2 || r4c1 == r2c1 || r4c1 == r1c1 )
		r4c1 = rand () % 4 + 1;
		if ( r4c2 == r4c1 || r4c2 == r4c3 || r4c2 == r4c4 || r4c2 == r3c1 || r4c2 == r3c2 || r4c2 == r2c2 || r4c2 == r1c2 )
		r4c2 = rand () % 4 + 1;
		if ( r4c3 == r4c1 || r4c3 == r4c2 || r4c3 == r4c4 || r4c3 == r3c3 || r4c3 == r3c4 || r4c3 == r2c3 || r4c3 == r1c3 )
		r4c3 = rand () % 4 + 1;
		if ( r4c4 == r4c1 || r4c4 == r4c2 || r4c4 == r4c3 || r4c4 == r3c3 || r4c4 == r3c4 || r4c4 == r2c4 || r4c4 == r1c4 )
		r4c4 = rand () % 4 + 1;
	int line = 0;
	while ( line <= 4 )
	{
		switch ( line )
		{
			case 0:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << " " << "\t|";
			 	cout << "\t" << r1c2 << "\t|";
		 		cout << "\t" << " " << "\t|";
		 		cout << "\t" << r1c4 << "\t|\n";
				line++;
	 		case 1:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << r2c1 << "\t|";
	 			cout << "\t" << r2c2 << "\t|";
	 			cout << "\t" << " " << "\t|";
	 			cout << "\t" << " " << "\t|\n";
				line++;
	 		case 2:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << " " << "\t|";
	 			cout << "\t" << " " << "\t|";
	 			cout << "\t" << r3c3 << "\t|";
	 			cout << "\t" << r3c4<< "\t|\n";
				line++;
	 		case 3:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << "\n|\t" << r4c1 << "\t|";
	 			cout << "\t" << " " << "\t|";
	 			cout << "\t" << r4c3 << "\t|";
	 			cout << "\t" << " " << "\t|\n";
	 			line++;
	 		case 4:
			for (int plus = 0 ; plus <= 65 ; plus++)
			{
				cout << "+";
			}
				cout << endl;
				line++;
		
		}
	}

btw...i cant use array.

You can't use arrays? Why on Earth not? I don't know why professors impose these types of stipulations. Regardless, you should probably create a function that checks for the legality of the Sudoku puzzle as you go and continually call it as you create the puzzle (or are you SOLVING the puzzle?).

Sudoku creation and solving is not a trivial task. You're going to need an algorithm, even if it's some type of non-optimal brute-force algorithm. Type "sudoku algorithm" into google. I've solved some fairly trivial ones using brute force, but beyond that, I haven't done much with Sudoku algorithms. Good luck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.