1. ## dice problem

i am trying to make a program to keep running (rolling of two dice) until the total of the two is 10 or 11.
which function and how can i use it to make the program stop running when the total of two dice equals 10 or 11.
i tried with the while loop but that didn't seen to work.

2. You may actually want to use a do-while loop here, so that the dice get rolled at least once. But either way should work. Post what you have.

3. ## dice ???

here is what i have. i can not figure out how to make the program stop running when (the point) or 7 are the newTotal.
i know how to do the count loops, but how do i take the count out.

insert
Code:
while (count<5){

printf("The new randon is %i\n",newTotal);

if (newTotal ==thePoint)
{printf("You win \n");
break;}
else if (newTotal==7)
{	printf("You loose\n");
break;}
else
{printf("Nothing\n");}

count++;}

4. So if you want to stop when newTotal is the point or 7, why don't you do
Code:
do
/* all your dice rolling */
while (newTotal != 7 && newTotal != thePoint)
/* Check results here */
Remember de Morgan's law: -(x or y) = -x and -y.

5. Code:
var faces
while faces != 10 AND faces != 11
do reroll
end while
The rest is basically arithmatic. And might I recommend that you use

rand() &#37; (6 - 1) + 1

because otherwise you would occassionally get 7 on a die.

6. i tried that
and this is what the compiler gives me
fatal error C1075: end of file found before the left brace '{' at (the file name)

7. Originally Posted by citizen
Code:
var faces
while faces != 10 AND faces != 11
do reroll
end while
The rest is basically arithmatic. And might I recommend that you use

rand() % (6 - 1) + 1

because otherwise you would occassionally get 7 on a die.
? % is remainder, so rand()%6 could only give 0, 1, 2, 3, 4, or 5.

8. i did that and still the same problem

9. Originally Posted by goran00
i tried that
and this is what the compiler gives me
fatal error C1075: end of file found before the left brace '{' at (the file name)
When you tried ... what? The do-while? You still need to enclose the statements in the loop in curly braces.

10. when i click the error this is the line it takes me to
#include <stdio.h>

11. i got the loops, the curly braces and still the same problem

12. Originally Posted by tabstop
? % is remainder, so rand()%6 could only give 0, 1, 2, 3, 4, or 5.
Hm, well that's right. But a normal six sided die does not have a zero face, so some effort to squeeze the range of rand into 1 to 6 inclusive is necessary. That's pretty much the only way I know how to do it also.

13. thats good. it works not its giving me another error
error C2061: syntax error : identifier 'rollADie2'
what does that mean

14. Post your code. You do have a main() function, right? And you have all your variables declared somewhere, right?

15. Code:
include <stdio.h>
#include <stdlib.h>
#include <time.h>

main(){
int comeOutRoll;
int count;
int thePoint;
int newTotal;

srand(time(NULL));
count=0;
thePoint=0;

printf("%i\n",comeOutRoll);

if (comeOutRoll == 7)
{printf("Winner\n");}
else if (comeOutRoll == 11)
{printf("Winner\n");}
else if (comeOutRoll ==2)
{printf("You loose\n");}
else if (comeOutRoll ==3)
{printf("You loose\n");}
else if (comeOutRoll ==12)
{printf("You loose\n");}

else
{printf("You might have a chance \n");
thePoint=comeOutRoll;
printf("The point is %i\n",thePoint);
do

printf("The new random is %i\n",newTotal);

if (newTotal ==thePoint)
{printf("You win \n");}
else if (newTotal==7)
{printf("You loose\n");}
else
{printf("Nothing\n");}

count++;
while (newTotal != thePoint && newTotal != 7);

}