A player rolls two dice. Each die has six
faces. These faces contain 1, 2, 3, 4, 5,
and 6 spots. After the dice have come to
rest, the sum of the spots on the two
upward faces is calculated.
If the sum is 7 or 11 on the first throw, the
player wins.
If the sum is 2, 3, or 12 on the first throw,
the player loses.
If the sum is 4, 5, 6, 8, 9, or 10 on the
first throw, then sum becomes the
player’s point. To win, you must continue
rolling the dice until you make your
points. The player loses by rolling a 7
before making the point.
This is my program:
- Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int rollDice (void);
main ( )
{
int Status, sum, Point;
srand (time(0));
sum = rollDice ( );
switch (sum)
{
case 7: case 11:
Status = 1;
break;
case 2: case 3: case 12:
Status = 2;
break;
default:
Status = 0;
Point = sum;
printf("Point is %d\n", Point);
break;
}
while (Status == 0)
{
sum = rollDice ( );
if (sum == Point)
Status = 1;
else
if (sum == 7)
Status = 2;
}
if (Status == 1)
printf ("Player wins\n");
else
printf ("Player loses\n");
}
int rollDice (void)
{
int die1, die2, workSum;
die1 = 1 + (rand ( ) % 6);
die2 = 1 + (rand ( ) % 6);
workSum = die1 + die2;
printf ("Player rolled %d + %d = %d\n", die1, die2, workSum);
}
I am really close to completing the program but my problem is that the player will always win and the program will not end at the correct spot. Any help that you can give me would be much appreciated. This is my first time on this forum so please excuse me if I have done something wrong.
Thanks



