Thread: Looping Error?

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    4

    Looping Error?

    Poker Game:

    this obviously isnt my full code but heres my problem. currentTurn which is nestled withmy loops is meant to go 0-4 (iNoOfPlayers) and repeat. but once it exits the inner Do-While loop it gets changed from 0 to 1. when it reenters the Loop currentTurn= 2293500.

    I'm completely stuck as to why this is.

    /*OUTPUT:
    Pot:0
    Player[0]'s Turn:
    Choose: Check[C]\Bet[B]\Fold[F]:
    C
    Player[1]'s Turn:2 # currentTurn=1
    Check[2293500]: # currentTurn=2293500
    Pot:0
    Player[2293500]'s Turn:
    Choose: Check[C]\Bet[B]\Fold[F]:
    C
    */


    Code:
    	int startTurn = 0;
    	int currentTurn = startTurn;
    	int exit = 0;
    	while((noWinner() && exit == 0) != 0)
    	{
    		shuffleDeck(Deck);
    		for(i=0 ; i<4 ; i++)
    		{
    			deal(i, startTurn);
    			resetStats();
    			do
    			{
    				currentTurn = currentTurn % iNoOfPlayers;
    				printf( "Pot:%d\n", pot);
    				printf( "Player[%d]'s Turn:\n", currentTurn);
    				choose(currentTurn);
    				currentTurn = ++currentTurn % iNoOfPlayers;
    				printf( "Player[%d]'s Turn:%d\n", currentTurn, iNoOfPlayers);
    			}while(!(equalBets(currentTurn)));
    		}
    		startTurn = ++startTurn % iNoOfPlayers;
    		printf( "StartTurn[%d] Enter 1 to Exit:\n", startTurn);	
    		scanf("%d", &exit);
    	}
    ive omitted various function cos my code is long(and in various files) but this is where the error is (i think).

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    43
    looks to me like the problem is probably in your equalBets function. Try posting that.

  3. #3
    Registered User
    Join Date
    Feb 2006
    Posts
    4
    Code:
    int equalBets(int turn)
    {	
    	extern player Player[];
    	int i;
    	printf("%d",turn);
    	for (i=0 ; i<iNoOfPlayers ; i++)
    	{
    		if (Player[i].hand[0].index != -1 && bet[i] != currBet)
    		{
    			return 0;
    		}
    	}
    	return 1;
    }
    turn was only added to check the value of currentTurn from its calling function. turn ends up = 2293500.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM