hi there,
I am creating a C boardgame, and my program isnt working very well. I narrowed it down to the function shown below. The purpose of this function is to keep track of the total numbers of spaces player1 moves in the game, how much more spaces the player has to move in order to win. Oh and it also has some validation. They are 2 of these function in my program.
Now the problem that I am having is with the part where the function is to keep track of the total numbers of spaces player1 moves in the game and how much more spaces the player has to move in order to win.
Code:
int players_move_spaces(int array1[],int die2)
{
static int num2;
int left_over2;
num2=num2 + die2; //die represents the value that was obtained by spinning the dice
//num2 stores the total value of all the numbers obtained by spinng the dice
array1[num2]=num2; //array moves to num2's position
printf("You have just moved %d spaces",num2);
left_over2= SIZE - num2; //how much more spaces the player has to move in order to win. SIZE is 25 cuz they r 25 spacesin the array
if(die2 < left_over2 )
{
printf("\n");
printf("You have %d more spaces to move in order to win ",left_over2);
}
else
if(die2 > left_over2 )
{
printf("Sorry you must forfeit a turn ");
printf("\n");
printf("They are not enough spaces. ");
}
if(num2==SIZE)
{
printf(" CONGRADULATIONS !! Player 2 won the game ");
}
return num2;
}
What i realise, is that the function is some times displaying 2 of the printf statements contained in first 2 if statements which is incorrect. If any help can be offered i would greatly appreciate it.