![]() |
| | #1 |
| Guest
Posts: n/a
| Can I get this to loop back? Thanks for reading. |
|
| | #2 |
| .... Join Date: Aug 2001 Location: Groningen (NL)
Posts: 2,386
| Try something like this: Code: for (i = 0; i < MAX; i++)
{
...
if (restart)
{
i = 0;
}
...
}
|
| Shiro is offline | |
| | #3 |
| Registered User Join Date: Feb 2002
Posts: 591
| Yes there is ,add a "i < 3;" To line 28 in your code. |
| Barjor is offline | |
| | #4 |
| Guest Join Date: Aug 2001
Posts: 5,034
| |
| Sebastiani is offline | |
| | #5 |
| Guest
Posts: n/a
| This is the for loop right now... in 'checkforwin' if somebody wins 'win' will equal 1, to stop the while loop, so I'm trying to find a way to get it out of the while loop, and back to the beginning of the for loop. for (game = 0; game < 4; game = game + 1); { clrscr(); board(300,80); while(win == 0) { xmove(); checkforwin(); omove(); checkforwin(); } } |
|
| | #6 |
| Guest
Posts: n/a
| I managed to get it top stop asking for moves after somebody has won, but the program will exit, instead of going back to the to the beginning of the for loop.. for (game = 0; game < 4; game = game + 1); { board(300,80); while (win < 1) { xmove(); checkforwin(); if (win < 1) { omove(); checkforwin(); } } } |
|
| | #7 |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| What are you calling to make the prog exit? Is it return or exit()? If so, you need to re-think how that works. If you get stuck, post a snippet of real code here, and don't forget to use code tags when doing so please. The basics in your psuedo code look OK to me, so you can't be far off the mark.
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #8 |
| Guest
Posts: n/a
| I'm using return to close the whole program... Here's the checkforwin function with the main again: Code:
void checkforwin() //Checks if either team has won.
{
// X's win.
if( (square1==1 && square2==1 && square3==1) || (square4==1 && square5==1 && square6==1) || (square7==1 && square8==1 && square9==1) ) //Horizontal
wins.
{
printf("Tic Tac Toe! The X's win! X-cellent job! \n");
player1win = player1win + 1;
win = win + 1;
}
if( (square1==1 && square4==1 && square7==1) || (square2==1 && square5==1 && square8==1) || (square3==1 && square6==1 && square9==1) ) //Vertical
wins.
{
printf("Tic Tac Toe! The X's win! X-cellant job! \n");
player1win = player1win + 1;
win = win + 1;
}
if( (square1==1 && square5==1 && square9==1) || (square3==1 && square5==1 && square7==1) ) //Diagonal Wins.
{
printf("Tic Tac Toe! The X's win! X-cellant job! \n");
player1win = player1win + 1;
win = win + 1;
}
// O's win.
if( (square1==2 && square2==2 && square3==2) || (square4==2 && square5==2 && square6==2) || (square7==2 && square8==2 && square9==2) ) //Horizontal
wins.
{
printf("Tic Tac Toe! The O's win! Neat-O job! \n");
player2win = player2win + 1;
win = win + 1;
}
if( (square1==2 && square4==2 && square7==2) || (square2==2 && square5==2 && square8==2) || (square3==2 && square6==2 && square9==2) ) //Vertical
wins.
{
printf("Tic Tac Toe! The O's win! Neat-O job! \n");
player2win = player2win + 1;
win = win + 1;
}
if( (square1==2 && square5==2 && square9==2) || (square3==2 && square5==2 && square7==2) ) //Diagonal Wins
{
printf("Tic Tac Toe! The O's win! Neat-O job! \n");
player2win = player2win + 1;
win = win + 1;
}
// Cat's Game.
if ((square1 != 0 && square2 != 0) && (square3 != 0) && (square4 != 0) && (square5 != 0) && (square6 != 0) && (square7 != 0) && (square8 != 0) &&
(square9 != 0) && (win == 0))
{
printf("Cat's Game! X's and O's are tied! \n");
win = win + 1;
}
}
int main()
{
int gdriver = DETECT, gmode; //Determines graphics driver and mode to use.
initgraph(&gdriver, &gmode, " "); //Switches to graphics mode.
player1win = 0;
player2win = 0;
gamecount = 1;
for (game = 0; game <= 3; game = game + 1); //Tic Tac Toe is played 3 times.
{
win = 0;
square1 = 0;
square2 = 0;
square3 = 0;
square4 = 0;
square5 = 0;
square6 = 0;
square7 = 0;
square8 = 0;
square9 = 0;
board(300,80);
printf("\n \n \n \n \n \n \n");
printf("GAME %d \n", gamecount);
while (win < 1)
{
xmove();
checkforwin();
if (win < 1)
{
omove();
checkforwin();
}
}
}
getchar();
return(0);
}
|
|
| | #9 |
| Guest
Posts: n/a
| I just found this out, my for loop works fine without graphics... The 'xmove' , 'omove' and 'board' are all graphics, does that affect the for loop? |
|
| | #10 | |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| Quote:
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] | |
| Hammer is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Link to DLL with LoadLibrary corrupts control loop | Ramses800 | C Programming | 8 | 12-01-2008 10:09 AM |
| Mutiliplcation Program that uses a (do, while, and for loop)? | Debbie Bremer | C++ Programming | 4 | 10-11-2008 06:04 PM |
| Can a "switch" be inside a loop? | gmk0351 | C Programming | 5 | 03-28-2008 05:47 PM |
| syntax question | cyph1e | C Programming | 19 | 03-31-2006 12:59 AM |
| How to change recursive loop to non recursive loop | ooosawaddee3 | C Programming | 1 | 06-24-2002 08:15 AM |