I am writing a snakes and ladder program and I'm almost finished, but I am struggling with the dice to work in the way I want it to work.
I want the dice to work like this :
Before each player throw the dice they must start at 0.
Each player must throw a 6 on the dice to move on the board.
If a player threw a 6 on the dice, that player can throw again.
But I ended up with two seperate dice, one for each player (game is only for two players).And when I run the program, both players don't start at 0. And when I throw the dice, both players move at the same time but with different values.
If one of my players threw a 6, they just keep on throwing until someone wins the game. I tried to use a switch and if statements but I couldn't get it right.
And so I did this :
Can someone please tell me what I'm doing wrong or give me hints on what to do.
#define SpaceBar 32// 32 is an ASCII value for a spacebar
int dice, null, score=0;
int X, Y;
int score,above, dice2, score2, above2;
int main(void)// main function
system("cls");// this is only to clear the screen and print the new values
ThrowDice();// the throw dice function
Select = getch();//select spacebar input if pressed, to roll the dice once
printf("congratulaions Player 1 won the game");
printf("congratulations Player 2 won the game");
while(Select == SpaceBar);
void ThrowDice()//dice function
printf("the dice rolled = %d", dice);
printf("\nPlayer1 current position = %d\n",score);
srand(time(null));//to make the dice random
dice =(rand() % 6) + 1;//dice
score=score+dice;//total score of dice throws
if(score >100)//player must land on 100 exactly.
above = (score-100);
score = (100 - above);
switch(score)//this all my snakes and ladders for player 1
case 28 :score=8;break;
case 57 :score=37;break;
case 81 :score=61;break;
case 91 :score=50;break;
case 97 :score=84;break;
case 16 :score=25;break;
case 32 :score=52;break;
case 39 :score=79;break;
case 75 :score=86;break;
//This is my Player 2 section starting from here on.
printf("the dice rolled = %d", dice2);
printf("\nPlayer2 current position = %d\n",score2);
srand(time(null));// to make dice random
dice2 =(rand() % 6) + 1;// diece
score2=score2+dice2;// total dice throws for player 2
if(score2 >100)// must land on 100 exactly
above2 = (score2-100);
score2 = (100 - above2);
switch(score2)// all the snakes and ladders for player 2
case 28 :score2=8;break;
case 57 :score2=37;break;
case 81 :score2=61;break;
case 91 :score2=50;break;
case 97 :score2=84;break;
case 16 :score2=25;break;
case 32 :score2=52;break;
case 39 :score2=79;break;
case 75 :score2=86;break;