I’m trying to make some sort of non-graphic version of a game. It involves two dices and when you roll any number besides the ones listed, you roll again until you get the one on the first roll. What have I done wrong or is there another way to select another random number for d1 and d2.
void setup()
{
int d1 = (int) random (6) + 1;
int d2 = (int) random (6) + 1;
int sum = 0;
int point = d1 + d2;
println (d1 + ", " + d2);
switch (point)
{
case 2:
case 3:
case 12: println ("You lose.");
break;
case 7:
case 11: println ("You win.");
break;
default: sum += point;
int d1 = (int) random (6) + 1;
int d2 = (int) random (6) + 1;
int point = d1 + d2;
println (d1 + ", " + d2);
switch (point)
{
case 7: println ("You lose.");
break;
default: while (sum != point)
{
int d1 = (int) random (6) + 1;
int d2 = (int) random (6) + 1;
int point = d1 + d2;
println (d1 + ", " + d2);
}
}
}
}