# Tutorial 38 challenge

 Akshay B P · November 8, 2014 program.cbpEach time I run the program, the same number is being generated.What should I do ?#include #include #include #include #include int main(){    int a,b;char x;    int diceroll1,diceroll2,diceroll3;    diceroll1=(rand()%6) + 1;    diceroll2=(rand()%6) + 1;    diceroll3=(rand()%6) + 1;    a = diceroll1+diceroll2+diceroll3;    printf("%d \n", a);    printf("Guess the next turn (l,h,s) \n");    scanf("%c",&x);    diceroll1=(rand()%6) + 1;    diceroll2=(rand()%6) + 1;    diceroll3=(rand()%6) + 1;    b = diceroll1+diceroll2+diceroll3;    printf("%d \n", b);    if(((a>b)&&(x=='l'))||((a

## Replies

 Brian Linaburg · December 5, 2014 I was having the same problem with the random numbers being the same each time also. Thanks Tyler for posting your code. I haven't learned about srand yet, so it helped out a lot. #include #include #include  //thanks T.B.int main(){    char guess;    int i;    int diceRoll;    int total1 =0;    int total2 =0;        srand(time(0));  //thanks T.B.        for(i=0; i < 3; i++){        diceRoll = ( rand()%6)+1;        printf("%d \t", diceRoll);        total1 = total1+diceRoll;    }        printf("\nTotal first total is %d \n", total1);    printf("Next round higher, lower, or same? (h/l/s) \n");    scanf("%c", &guess);        for (i=0; i < 3; i++) {        diceRoll = ( rand()%6)+1;        printf("%d \t", diceRoll);        total2 = total2+diceRoll;    }        printf("\nThe second total is %d \n", total2);        if (total1>total2) {        if (guess == 'l') {            printf("Winner \n");        }else{            printf("Try Again \n");        }    }    if (total1#include #include int main() {//Declarationsint roll1, roll2, roll3, total1 = 0, total2 = 0, i;char guess;//Rng roll 1srand(time(0));roll1 = ( rand()%6 ) + 1;printf("First roll: %d, ", roll1);roll2 = ( rand()%6 ) + 1;printf("Second roll: %d, ", roll2);roll3 = ( rand()%6 ) + 1;printf("Third roll: %d, ", roll3);total1 = (roll1 + roll2 + roll3);printf("First roll total: %d \n", total1);//Ask for guessprintf("Guess whether the next roll is bigger ('b'), smaller ('s'), or the same ('s') by entering the corresponding single letters<<\n");scanf("%c", &guess);//Rng roll 2roll1 = ( rand()%6 ) + 1;printf("First roll: %d, ", roll1);roll2 = ( rand()%6 ) + 1;printf("Second roll: %d, ", roll2);roll3 = ( rand()%6 ) + 1;printf("Third roll: %d, ", roll3);total2 = (roll1 + roll2 + roll3);printf("Second roll total: %d\n", total2);//Conditionals: User guesses if ( ((total1 > total2) && (guess == 's')) || ((total1 < total2) && (guess == 'b')) || ((total1 == total2) && (guess == 's')) )printf("Waiwaiwai---How'd you know?");elseprintf("Best 2 out of 3?");return 0;} You knees · November 10, 2014 I think this can help.
• 1

## C

129,824 followers