# Thread: having problems with my if statements

1. ## having problems with my if statements

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.

2. i have been here sitting for hours and still there is no progress so i have decided to post the program. I am using Microsoft Visual Studio.NET 2003. I am trying to teach myself C, so it isnt anything fancy I am only including the .cpp file

3. move your printf statement outside the while loop.
Code:
`printf("Player one must play first");`
while you are at it, intialize dice and dice2 to 0, otherwise you get warning messages.

4. This is the C board, so stop compiling as C++. game.cpp

Quzah.

Popular pages Recent additions