F
FSX
Hello everyone,
I would like to quit the execution of the while as soon as the program
reaches 50 points, so that a player wins. Here is both the pastebin page
and the source (but I think the pastebin page is better).
Should I create two distinct while loops? I tried to add a control
statement that breaks the while before the adding cycle but it still go
beyond 50 (to 70, it executes another turn).
Thank in advance to everyone.
FSX
http://fsx.pastebin.com/m203bc77
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int dice1, dice2, score1, score2;
srand((unsigned)time(NULL));
dice1 = dice2 = score1 = score2 = 0;
while(score1 < 50 && score2 < 50)
{
if(score1 >= 50 || score2 >= 50)
break;
//player 1
dice1 = (rand()%6)+1;
dice2 = (rand()%6)+1;
if(dice1 == dice2)
{
printf("Player 1 scored double %d\n", dice1);
if(dice1 == 3)
score1 = 0;
else if(dice1 == 6)
score1 = score1 + 25;
else
score1 = score1 + 5;
printf("Player 1 = %d\n", score1);
}
//player 2
dice1 = (rand()%6)+1;
dice2 = (rand()%6)+1;
if(dice1 == dice2)
{
printf("Player 2 scored double %d\n", dice1);
if(dice2 == 3)
score2 = 0;
else if(dice2 == 6)
score2 = score2 + 25;
else
score2 = score2 + 5;
printf("Player 2 = %d\n", score2);
}
}
if(score1 == score2)
printf("Pari\n");
else if(score1 > score2)
printf("Player 1 Wins\n");
else
printf("Player 2 Wins\n");
return 0;
}
Posted using www.webuse.net
I would like to quit the execution of the while as soon as the program
reaches 50 points, so that a player wins. Here is both the pastebin page
and the source (but I think the pastebin page is better).
Should I create two distinct while loops? I tried to add a control
statement that breaks the while before the adding cycle but it still go
beyond 50 (to 70, it executes another turn).
Thank in advance to everyone.
FSX
http://fsx.pastebin.com/m203bc77
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int dice1, dice2, score1, score2;
srand((unsigned)time(NULL));
dice1 = dice2 = score1 = score2 = 0;
while(score1 < 50 && score2 < 50)
{
if(score1 >= 50 || score2 >= 50)
break;
//player 1
dice1 = (rand()%6)+1;
dice2 = (rand()%6)+1;
if(dice1 == dice2)
{
printf("Player 1 scored double %d\n", dice1);
if(dice1 == 3)
score1 = 0;
else if(dice1 == 6)
score1 = score1 + 25;
else
score1 = score1 + 5;
printf("Player 1 = %d\n", score1);
}
//player 2
dice1 = (rand()%6)+1;
dice2 = (rand()%6)+1;
if(dice1 == dice2)
{
printf("Player 2 scored double %d\n", dice1);
if(dice2 == 3)
score2 = 0;
else if(dice2 == 6)
score2 = score2 + 25;
else
score2 = score2 + 5;
printf("Player 2 = %d\n", score2);
}
}
if(score1 == score2)
printf("Pari\n");
else if(score1 > score2)
printf("Player 1 Wins\n");
else
printf("Player 2 Wins\n");
return 0;
}
Posted using www.webuse.net