Thread: Help plz

  1. #31
    Unregistered
    Guest
    sorry, 4got code

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h> /* sets up 2 strings so names can be used */
    char	oxo[4][4];
    void	display_grid(void);
    
    /*
     =================================================
     =================================================
     */
    
    int main(void)
    {
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    	int r1, c1, r0, c0, rx, cx, count;
    	int name1[20], name2[20];	/* defines name1 & name2 are variables */
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    	for (r1 = 1; r1 <= 3; r1++)
    	{
    		for (c1 = 1; c1 <= 3; c1++)
    		{
    			oxo[r1][c1] = '-';
    			oxo[0][1] = '1';	/**/
    			oxo[0][2] = '2';	/* prints column numbers */
    			oxo[0][3] = '3';	/**/
    			oxo[1][0] = '1';	/**/
    			oxo[2][0] = '2';	/* prints row numbers */
    			oxo[3][0] = '3';	/**/
    		}
    	}
    
    	system("clear"); /* clears the screen */
    
    	printf("\n Player 1 what is your name?\n"); /* asks player 1 1s name */
    
    	scanf("%s", name1); /* reads name */
    
    	printf("\nHello %s you place the '0's & you go first! \n", name1);	/* prints out */
    
    	printf("\n Player 2 what is your name?\n"); /* asks player 1 2s name */
    
    	scanf("%s", name2); /* reads name */
    
    	printf("\nHello %s you place the 'X's & you go second!\n", name2);	/* prints out */
    
    	system("clear"); /* clears screen */
    
    	display_grid();
    
    	count = 0;
    
    	while (count < 9)
    	{
    		if (count < 9)			
    		{
    			while (1)
    			{					/* start infinite loop, exits when user enters valid cell. */
    				printf(" %s (0's) enter vertical coordinate: ", name1); /* prints out */
    				while (scanf("%d", &r0) != 1)
    				{
    					printf("%d 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				printf(" %s (0's) enter horizontal coordinate: ", name1); /* prints out */
    				while (scanf("%d", &c0) != 1)
    				{
    					printf("%s, 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				if ((r0 < 1) || (r0 > 3) || (c0 < 1) || (c0 > 3))
    				{
    					printf("Out of range grid is 3x3, enter 1-3, vertical then space bar then horizontal co-ordinate, try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    
    				if (oxo[r0][c0] == 'X' || oxo[r0][c0] == '0')
    				{
    					printf("Cell already taken, please try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    				printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N\n", r0, c0);
    				{
    					int c;
    					getchar();
    					c = getchar();
    					if (c != 'q' && c != 'Q') return (0); 
    
    					if (c != 'y' && c != 'Y')
    						continue;
    				}
    				break;			/* leave the infitite loop */
    			}
    
    			oxo[r0][c0] = '0';
    			count++;
    		}
    
    		display_grid();
    
    		/*
    		 * These lines look to see if there is
    		 * a row of 0s in any of the 8 ways
    		 * possible program looks to see if 0s
    		 * have won
    		 */
    		if
    		(
    			(oxo[1][1] == '0' && oxo[1][2] == '0' && oxo[1][3] == '0')
    		||	(oxo[2][1] == '0' && oxo[2][2] == '0' && oxo[2][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[3][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][1] == '0' && oxo[3][1] == '0')
    		||	(oxo[1][2] == '0' && oxo[2][2] == '0' && oxo[3][2] == '0')
    		||	(oxo[1][3] == '0' && oxo[2][3] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[2][2] == '0' && oxo[1][3] == '0')
    		)
    		{
    			printf("\n GAME OVER...%s WINS.... GAME OVER\n", name1);	/* if 0 wins print this */
    
    			return;						/* if '0' wins end game */
    		}
    		else
    		{								/* if 0 not won program continues */
    			if (count < 9)			/*  */
    			{
    				while (1)
    				{					/* start infinite loop, exits when user enters valid cell. */
    					printf(" %s (X's) enter vertical coordinate: ", name2);
    					while (scanf("%d", &rx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					printf(" %s (X's) enter horizontal coordinate: ", name2);
    					while (scanf("%d", &cx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					if ((rx < 1) || (rx > 3) || (cx < 1) || (cx > 3))
    					{
    						printf("Out of range grid is 3x3, enter 1-3 vertical then space bar then horizontal co-ordinate, try again\n");
    						continue;	/* go back to top of infinite loop */
    					}
    
    					if (oxo[rx][cx] == 'X' || oxo[rx][cx] == '0')
    					{
    						printf("Cell already taken\n");
    						continue;	/* go back to top of infinite loop */
    					}
    					printf("the co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N?\n", rx, cx);
    					{
    						int c;
    						getchar();
    						c = getchar();
    						
    						if (c != 'q' && c != 'Q') return (0); 
    						
    						if (c != 'y' && c != 'Y')
    							continue;
    					}
    					break;			/* leave the infitite loop */
    				}
    
    				oxo[rx][cx] = 'X';
    				count++;
    			}
    
    			display_grid();
    
    			/*
    			 * These lines look to see if
    			 * there is a row of Xs in any
    			 * of the 8 ways possible
    			 * program looks to see if Xs
    			 * have won
    			 */
    			if
    			(
    				(oxo[1][1] == 'X' && oxo[1][2] == 'X' && oxo[1][3] == 'X')
    			||	(oxo[2][1] == 'X' && oxo[2][2] == 'X' && oxo[2][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[3][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][1] == 'X' && oxo[3][1] == 'X')
    			||	(oxo[1][2] == 'X' && oxo[2][2] == 'X' && oxo[3][2] == 'X')
    			||	(oxo[1][3] == 'X' && oxo[2][3] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[2][2] == 'X' && oxo[1][3] == 'X')
    			)
    			{
    				printf("\nGAME OVER...%s WINS!!... GAME OVER\n", name2);
    
    				/* if X wins print this */
    				return;				/* if X wins end game */
    			}
    		}
    
    		if (count == 9)
    		{					/* when 9 moves have been made with no winner game stops */
    			system("clear");
    			printf("\nGAME OVER...NO WINNER!!...GAME OVER\n");	/* print information telling users out */
    		}
    	}
    }
    
    /*
     =================================================
     =================================================
     */
    void display_grid(void)
    {
    	/*~~~~~~~~~*/
    	int row, col;
    	/*~~~~~~~~~*/
    
    	system ("clear");
    	for (row = 1; row <= 3; row++)
    	{
    		for (col = 1; col <= 3; col++)
    		{
    			printf(" %c |", oxo[row][col]); /* prints & spaces vertical g grid lines */
    		}
    
    		printf("\n");
    
    		if (row <= 3)
    		{
    			printf(" ------------\n");	/* prints & spaces horizontal g grid lines */
    		}
    	}
    
    	return;
    }

  2. #32
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Unregistered
    ...I did exactly what u said Hammer, can u see what is goin wrong??
    Yep, it's me this time Told you the wrong thing, sorry.

    This
    >if (c != 'q' && c != 'Q') return (0);

    should have said this
    >if (c == 'q' || c == 'Q') return (0);

    Change the two entries and have another go!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #33
    Unregistered
    Guest

    Unhappy

    Code below works, but when this question is displayed:

    e.g.
    printf(" %s (X's) enter vertical coordinate: ", name2);
    if "1 2" (all on this question rather than waiting 4 horizontal question to be asked) is entered all on that line, it accepts it, is there a way to display the error message if more than 1 character is entered?

    I thought "!=1" restricted this, but it obviously isnt...??

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h> /* sets up 2 strings so names can be used */
    char	oxo[4][4];
    void	display_grid(void);
    
    /*
     =================================================
     =================================================
     */
    
    int main(void)
    {
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    	int r1, c1, r0, c0, rx, cx, count;
    	int name1[20], name2[20];	/* defines name1 & name2 are variables */
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    	for (r1 = 1; r1 <= 3; r1++)
    	{
    		for (c1 = 1; c1 <= 3; c1++)
    		{
    			oxo[r1][c1] = '-';
    			oxo[0][1] = '1';	/**/
    			oxo[0][2] = '2';	/* prints column numbers */
    			oxo[0][3] = '3';	/**/
    			oxo[1][0] = '1';	/**/
    			oxo[2][0] = '2';	/* prints row numbers */
    			oxo[3][0] = '3';	/**/
    		}
    	}
    
    	system("clear"); /* clears the screen */
    
    	printf("\n Player 1 what is your name?\n"); /* asks player 1 1s name */
    
    	scanf("%s", name1); /* reads name */
    
    	printf("\nHello %s you place the '0's & you go first! \n", name1);	/* prints out */
    
    	printf("\n Player 2 what is your name?\n"); /* asks player 1 2s name */
    
    	scanf("%s", name2); /* reads name */
    
    	printf("\nHello %s you place the 'X's & you go second!\n", name2);	/* prints out */
    
    	system("clear"); /* clears screen */
    
    	display_grid();
    
    	count = 0;
    
    	while (count < 9)
    	{
    		if (count < 9)			
    		{
    			while (1)
    			{					/* start infinite loop, exits when user enters valid cell. */
    				printf(" %s (0's) enter vertical coordinate: ", name1); /* prints out */
    				while (scanf("%d", &r0) != 1)
    				{
    					printf("%s, 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				printf(" %s (0's) enter horizontal coordinate: ", name1); /* prints out */
    				while (scanf("%d", &c0) != 1)
    				{
    					printf("%s, 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				if ((r0 < 1) || (r0 > 3) || (c0 < 1) || (c0 > 3))
    				{
    					printf("Out of range grid is 3x3, enter 1-3, vertical then space bar then horizontal co-ordinate, try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    
    				if (oxo[r0][c0] == 'X' || oxo[r0][c0] == '0')
    				{
    					printf("Cell already taken, please try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    				printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N\n", r0, c0);
    				{
    					int c;
    					getchar();
    					c = getchar();
    					if (c == 'q' || c == 'Q') return (0);  
    
    					if (c != 'y' && c != 'Y')
    						continue;
    				}
    				break;			/* leave the infitite loop */
    			}
    
    			oxo[r0][c0] = '0';
    			count++;
    		}
    
    		display_grid();
    
    		/*
    		 * These lines look to see if there is
    		 * a row of 0s in any of the 8 ways
    		 * possible program looks to see if 0s
    		 * have won
    		 */
    		if
    		(
    			(oxo[1][1] == '0' && oxo[1][2] == '0' && oxo[1][3] == '0')
    		||	(oxo[2][1] == '0' && oxo[2][2] == '0' && oxo[2][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[3][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][1] == '0' && oxo[3][1] == '0')
    		||	(oxo[1][2] == '0' && oxo[2][2] == '0' && oxo[3][2] == '0')
    		||	(oxo[1][3] == '0' && oxo[2][3] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[2][2] == '0' && oxo[1][3] == '0')
    		)
    		{
    			printf("\n GAME OVER...%s WINS.... GAME OVER\n", name1);	/* if 0 wins print this */
    
    			return;						/* if '0' wins end game */
    		}
    		else
    		{								/* if 0 not won program continues */
    			if (count < 9)			/*  */
    			{
    				while (1)
    				{					/* start infinite loop, exits when user enters valid cell. */
    					printf(" %s (X's) enter vertical coordinate: ", name2);
    					while (scanf("%d", &rx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					printf(" %s (X's) enter horizontal coordinate: ", name2);
    					while (scanf("%d", &cx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					if ((rx < 1) || (rx > 3) || (cx < 1) || (cx > 3))
    					{
    						printf("Out of range grid is 3x3, enter 1-3 vertical then space bar then horizontal co-ordinate, try again\n");
    						continue;	/* go back to top of infinite loop */
    					}
    
    					if (oxo[rx][cx] == 'X' || oxo[rx][cx] == '0')
    					{
    						printf("Cell already taken\n");
    						continue;	/* go back to top of infinite loop */
    					}
    					printf("the co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N?\n", rx, cx);
    					{
    						int c;
    						getchar();
    						c = getchar();
    						
    						if (c == 'q' || c == 'Q') return (0); 
    						
    						if (c != 'y' && c != 'Y')
    							continue;
    					}
    					break;			/* leave the infitite loop */
    				}
    
    				oxo[rx][cx] = 'X';
    				count++;
    			}
    
    			display_grid();
    
    			/*
    			 * These lines look to see if
    			 * there is a row of Xs in any
    			 * of the 8 ways possible
    			 * program looks to see if Xs
    			 * have won
    			 */
    			if
    			(
    				(oxo[1][1] == 'X' && oxo[1][2] == 'X' && oxo[1][3] == 'X')
    			||	(oxo[2][1] == 'X' && oxo[2][2] == 'X' && oxo[2][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[3][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][1] == 'X' && oxo[3][1] == 'X')
    			||	(oxo[1][2] == 'X' && oxo[2][2] == 'X' && oxo[3][2] == 'X')
    			||	(oxo[1][3] == 'X' && oxo[2][3] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[2][2] == 'X' && oxo[1][3] == 'X')
    			)
    			{
    				printf("\nGAME OVER...%s WINS!!... GAME OVER\n", name2);
    
    				/* if X wins print this */
    				return;				/* if X wins end game */
    			}
    		}
    
    		if (count == 9)
    		{					/* when 9 moves have been made with no winner game stops */
    			system("clear");
    			printf("\nGAME OVER...NO WINNER!!...GAME OVER\n");	/* print information telling users out */
    		}
    	}
    }
    
    /*
     =================================================
     =================================================
     */
    void display_grid(void)
    {
    	/*~~~~~~~~~*/
    	int row, col;
    	/*~~~~~~~~~*/
    
    	system ("clear");
    	for (row = 1; row <= 3; row++)
    	{
    		for (col = 1; col <= 3; col++)
    		{
    			printf(" %c |", oxo[row][col]); /* prints & spaces vertical g grid lines */
    		}
    
    		printf("\n");
    
    		if (row <= 3)
    		{
    			printf(" ------------\n");	/* prints & spaces horizontal g grid lines */
    		}
    	}
    
    	return;
    }

  4. #34
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK..... lets have quick re-think on the code posting front Now that you have a prog that works, try to post only a relevant section of code, not the whole program. It'll make it easier for people to read and understand what you mean when you ask questions. If you or someone else thinks the whole prog is needed, then by all means, post it, but only if necessary.

    Now, to answer your question:
    When a user enters 1 2, the scanf() function you are using will read the input up until the first non-numeric character, in this case it's the space in between the two numbers. The remaining input is left in the buffer, and gets read by the next call to scanf(). Personally, for the code you're writing, I'd leave it at that, allowing the user to type in advance if they know they can.

    The alternative is either (1) fflush() the input buffer, which is undefined, and therefore bad, or (2) rewrite the way in which you get data from the user.

    Personally, I go for option 2. You can look at this thread for some help on this type of thing.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #35
    Unregistered
    Guest
    ^^^

    2 final things, I would like to finish my code is:

    after:

    printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N, press q to quit\n", r0, c0);

    if 'q' is pressed by the user, i would like to make sure the user is sure, so I would like it to:

    printf("Are you sure you would like to quit the game, Y/N?\n");

    is 'y' is entered:

    printf("Thank you for playing, bye"\n);

    ----last thing
    printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N, press q to quit, press g to start new game\n" r0, c0);

    if 'g' is entered

    printf("Are you sure you would like to start a new game\n");

    Im not sure how to loop it so its starts a new game...??
    Can u help me Hammer, this is the last thing going to be added to my code, if u cud help it would b very much appreciated, thx.

  6. #36
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Are you winding me up, or wot?!
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #37
    Unregistered
    Guest
    No, I wasnt, sorry, but I just want to get this program perfect, and this is the last thing, PROMISE!! Im just not sure where to put the print staements, this is what I have come up with:
    Ive put a few comments in where im not sure:


    Code:
    printf("the co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N?\n", rx, cx);
    					{
    						int c;
    						getchar();
    						c = getchar();
    						
    						if (c == 'q' || c == 'Q');
    							printf("Are you sure you would like to quit? Y/N/n");
    						if (c != 'y' && c != 'Y') 
    						printf("Thank you 4 playing/n");
    						return (0); /*NOT SURE IF THIS IS CORRCT */
    							 
    						
    						if (c != 'y' && c != 'Y')
    							continue;
    
    						if (c != 'g' && c != 'G')
    				NOT SURE HOW TO LOOP BACK AND START NEW GAME!!!
    					}
    					break;			/* leave the infitite loop */
    				}

  8. #38
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    OK, I believe you!
    Code:
    printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N\n", r0, c0);
    {
    	int c;
    	getchar();
    	c = getchar();
    	if (c == 'q' || c == 'Q')
    	{
    		printf("Are you sure you would like to quit? Y/N\n");
    		getchar();
    		c = getchar();
    		if (c == 'y' || c == 'Y')
    		{
    			printf("Thank you 4 playing\n");
    			return (0);
    		}
    		continue;
    	}
    
    	if (c != 'y' && c != 'Y')
    		continue;
    }
    This will do the confirmation bit for quiting the game. It is not so easy to do the other bit (restarting) as the program is only designed to run once.

    Watch out for those { and } when you put this code back in.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  9. #39
    Unregistered
    Guest
    Code:
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h> /* sets up 2 strings so names can be used */
    char	oxo[4][4];
    void	display_grid(void);
    
    /*
     =================================================
     =================================================
     */
    
    int main(void)
    {
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    	int r1, c1, r0, c0, rx, cx, count;
    	int name1[20], name2[20];	/* defines name1 & name2 are variables */
    	/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
    
    	for (r1 = 1; r1 <= 3; r1++)
    	{
    		for (c1 = 1; c1 <= 3; c1++)
    		{
    			oxo[r1][c1] = '-';
    			oxo[0][1] = '1';	/**/
    			oxo[0][2] = '2';	/* prints column numbers */
    			oxo[0][3] = '3';	/**/
    			oxo[1][0] = '1';	/**/
    			oxo[2][0] = '2';	/* prints row numbers */
    			oxo[3][0] = '3';	/**/
    		}
    	}
    
    	system("clear"); /* clears the screen */
    
    	printf("\n Player 1 what is your name?\n"); /* asks player 1 1s name */
    
    	scanf("%s", name1); /* reads name */
    
    	printf("\nHello %s you place the '0's & you go first! \n", name1);	/* prints out */
    
    	printf("\n Player 2 what is your name?\n"); /* asks player 1 2s name */
    
    	scanf("%s", name2); /* reads name */
    
    	printf("\nHello %s you place the 'X's & you go second!\n", name2);	/* prints out */
    
    	system("clear"); /* clears screen */
    
    	display_grid();
    
    	count = 0;
    
    	while (count < 9)
    	{
    		if (count < 9)			
    		{
    			while (1)
    			{					/* start infinite loop, exits when user enters valid cell. */
    				printf(" %s (0's) enter vertical coordinate: ", name1); /* prints out */
    				while (scanf("%d", &r0) != 1)
    				{
    					printf("%s, 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				printf(" %s (0's) enter horizontal coordinate: ", name1); /* prints out */
    				while (scanf("%d", &c0) != 1)
    				{
    					printf("%s, 1 number was not entered, please try again\n", name1);
    					getchar();	/* needed to remove non-numeric character from input stream, I believe */
    				}
    
    				if ((r0 < 1) || (r0 > 3) || (c0 < 1) || (c0 > 3))
    				{
    					printf("Out of range grid is 3x3, enter 1-3, vertical then space bar then horizontal co-ordinate, try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    
    				if (oxo[r0][c0] == 'X' || oxo[r0][c0] == '0')
    				{
    					printf("Cell already taken, please try again\n");
    					continue;	/* go back to top of infinite loop */
    				}
    				printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N\n", r0, c0);
    				{
    					int c;
    					getchar();
    					c = getchar();
    					if (c == 'q' || c == 'Q')
    				{
    				printf("Are you sure you would like to quit? Y/N\n");
    					getchar();
    					c = getchar();
    					if (c == 'y' || c == 'Y')
    				{
    				printf("Thank you 4 playing\n");
    					return (0);
    		}
    		continue;
    	}
    
    	if (c != 'y' && c != 'Y')
    		continue;
    }
    
    
    				break;			/* leave the infitite loop */
    			}
    
    			oxo[r0][c0] = '0';
    			count++;
    		}
    
    		display_grid();
    
    		/*
    		 * These lines look to see if there is
    		 * a row of 0s in any of the 8 ways
    		 * possible program looks to see if 0s
    		 * have won
    		 */
    		if
    		(
    			(oxo[1][1] == '0' && oxo[1][2] == '0' && oxo[1][3] == '0')
    		||	(oxo[2][1] == '0' && oxo[2][2] == '0' && oxo[2][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[3][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][1] == '0' && oxo[3][1] == '0')
    		||	(oxo[1][2] == '0' && oxo[2][2] == '0' && oxo[3][2] == '0')
    		||	(oxo[1][3] == '0' && oxo[2][3] == '0' && oxo[3][3] == '0')
    		||	(oxo[1][1] == '0' && oxo[2][2] == '0' && oxo[3][3] == '0')
    		||	(oxo[3][1] == '0' && oxo[2][2] == '0' && oxo[1][3] == '0')
    		)
    		{
    			printf("\n GAME OVER...%s WINS.... GAME OVER\n", name1);	/* if 0 wins print this */
    
    			return;						/* if '0' wins end game */
    		}
    		else
    		{								/* if 0 not won program continues */
    			if (count < 9)			/*  */
    			{
    				while (1)
    				{					/* start infinite loop, exits when user enters valid cell. */
    					printf(" %s (X's) enter vertical coordinate: ", name2);
    					while (scanf("%d", &rx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					printf(" %s (X's) enter horizontal coordinate: ", name2);
    					while (scanf("%d", &cx) != 1)
    					{
    						printf("%s, 1 number was not entered, please try again\n", name2);
    						getchar();	/* needed to remove non-numeric character from input stream, I believe */
    					}
    					if ((rx < 1) || (rx > 3) || (cx < 1) || (cx > 3))
    					{
    						printf("Out of range grid is 3x3, enter 1-3 vertical then space bar then horizontal co-ordinate, try again\n");
    						continue;	/* go back to top of infinite loop */
    					}
    
    					if (oxo[rx][cx] == 'X' || oxo[rx][cx] == '0')
    					{
    						printf("Cell already taken\n");
    						continue;	/* go back to top of infinite loop */
    					}
    					printf("The co-ordinates you have chosen are %d (vertical) and %d (horizontal), are you sure this is the position you would like a '0' to be placed? Y/N\n", r0, c0);
    					{
    						int c;
    						getchar();
    						c = getchar();
    						if (c == 'q' || c == 'Q')
    					{
    					printf("Are you sure you would like to quit? Y/N\n");
    						getchar();
    						c = getchar();
    						if (c == 'y' || c == 'Y')
    					{
    					printf("Thank you 4 playing\n");
    						return (0);
    		}
    		continue;
    	}
    
    	if (c != 'y' && c != 'Y')
    		continue;
    }
    					
    
    
    					break;			/* leave the infitite loop */
    				}
    
    
    					break;			/* leave the infitite loop */
    				}
    
    				oxo[rx][cx] = 'X';
    				count++;
    			}
    
    			display_grid();
    
    			/*
    			 * These lines look to see if
    			 * there is a row of Xs in any
    			 * of the 8 ways possible
    			 * program looks to see if Xs
    			 * have won
    			 */
    			if
    			(
    				(oxo[1][1] == 'X' && oxo[1][2] == 'X' && oxo[1][3] == 'X')
    			||	(oxo[2][1] == 'X' && oxo[2][2] == 'X' && oxo[2][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[3][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][1] == 'X' && oxo[3][1] == 'X')
    			||	(oxo[1][2] == 'X' && oxo[2][2] == 'X' && oxo[3][2] == 'X')
    			||	(oxo[1][3] == 'X' && oxo[2][3] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[1][1] == 'X' && oxo[2][2] == 'X' && oxo[3][3] == 'X')
    			||	(oxo[3][1] == 'X' && oxo[2][2] == 'X' && oxo[1][3] == 'X')
    			)
    			{
    				printf("\nGAME OVER...%s WINS!!... GAME OVER\n", name2);
    
    				/* if X wins print this */
    				return;				/* if X wins end game */
    			}
    		}
    
    		if (count == 9)
    		{					/* when 9 moves have been made with no winner game stops */
    			system("clear");
    			printf("\nGAME OVER...NO WINNER!!...GAME OVER\n");	/* print information telling users out */
    		}
    	}
    }
    
    /*
     =================================================
     =================================================
     */
    void display_grid(void)
    {
    	/*~~~~~~~~~*/
    	int row, col;
    	/*~~~~~~~~~*/
    
    	system ("clear");
    	for (row = 1; row <= 3; row++)
    	{
    		for (col = 1; col <= 3; col++)
    		{
    			printf(" %c |", oxo[row][col]); /* prints & spaces vertical g grid lines */
    		}
    
    		printf("\n");
    
    		if (row <= 3)
    		{
    			printf(" ------------\n");	/* prints & spaces horizontal g grid lines */
    		}
    	}
    
    	return;
    }
    Ive tried everything, cant get it to work, can u c where im goin wrong??

  10. #40
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
        break;			/* leave the infitite loop */
    }
    
    
        break;			/* leave the infitite loop */
    }
    There are 2 in a row?! You've cut/paste a couple too many lines. Remove one set of them (that's a line with the break; and a line with a }
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #41
    Unregistered
    Guest
    Thank You!!!!! very very much, thx 4 stayin up late to help sort out my problems, good nite, sweet dreamzzZZZzzzzZzz..

  12. #42
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Bye bye now.....
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 09:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 12:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 08:44 AM