I'm trying to use loop...
But it seems a bit too complicated...
they are not that bad lol
basically look at this:
basically you see "while" "true" and "do this"Code:while(true) { //do this }
while is the type of loop. 2 main loops are "for" and "while" I like while the most. Basically this while loop will continue as long as the statement in side the () are true so 1==1 is always true and true is always true so it will always be true and basically be and infinite loop
it executes the stuff inside of the {} brackets which is just a comment so it will basically do nothing forever
This one does the same thing. It starts with "i" equaling 0, and keeps looping, every time increasing the value of i, and once i is not less than or equal to 10 it quits running the code.Code:int i = 0; while(i <= 10) { cout << "hello" << endl; i++; }
Make sense?
Control flow - Wikipedia, the free encyclopedia
Yeah.
Thanks blainsch~
Now I'm much more clear with the whole thing.
I need to int all the variables right? (ex: r1c2 for row1column 2)
hey i did it!!! this is only one block of 12. only copy paste and and change the variables. and i could introduce a function.
Code:for (int i=1; i<=4; ++i) { if (c1r1==i) for (int j=1; j<=4; ++j) { if (j==i) j++; if (j<=4 and c1r2==j) for (int k=1; k<=4; ++k) { if (k==i or k==j) k++; if (k==i or k==j) k++; if (k<=4 and c1r3==k) for (int l=1; l<=4; ++l) { if (l==i or l==j or l==k) l++; if (l==i or l==j or l==k) l++; if (l==i or l==j or l==k) l++; if (l<=4 and c1r4==l) point++; } } } }
Last edited by WingedPanther; 07-04-2009 at 05:08 AM. Reason: add code tags (the # button)
c1r1 is column 1 row 1.
for (int i=1; i<=4; ++i)
{
if (c1r1==i) for (int j=1; j<=4; ++j)
{
if (j==i) j++;
if (j<=4 and c1r2==j) for (int k=1; k<=4; ++k)
{
if (k==i or k==j) k++;
if (k==i or k==j) k++;
if (k<=4 and c1r3==k) for (int l=1; l<=4; ++l)
{
if (l==i or l==j or l==k) l++;
if (l==i or l==j or l==k) l++;
if (l==i or l==j or l==k) l++;
if (l<=4 and c1r4==l) point++;
}
}
}
}
hai.. i'm new to c++ but i quite like the code top there...
can some one help to explain it... when i see that quite confusing..
i hope genius around this site help to explain it.
It attempts to find (part of) a solution to a 4x4 sudoku through brute force. If you trace through the code by hand, you'll quickly see what it's doing.
ohhh, if w wanna make a sudoku, we have to use a nested loop,
Hint: 'structures'
These would allow you to group the data making up the Sudoku array without using arrays.
I'll leave it for you to stew over for a bit.![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks