# Challenge 2(Dice Roll) Completed :))

 osh Ranw · February 9, 2015 C Programming Tutorial - 38 Challenge #include #include #include #include #include int main(){int x = 0;int dice1 ,dice2 ,dice3 ;int sum0,sum1;char val; printf("press '0' or '\$'  to exit!!! \n");    dice1 = (rand()%6 + 1)  ;    dice2 = (rand()%6 + 1) ;    dice3 = (rand()%6 + 1) ;    sum0 = dice1 + dice2 +dice3 ;    printf("------------------------------------\n ");    printf("The Total Value Of The 3 Dice is:%d \n " , sum0 );    printf("------------------------------------\n ");    do{            x++;            if(x != 1){                sum0 = sum1  ;            }            printf(" \n\n Press Higher:h    Lower:l   Same:s \n ");            printf("If you think The Next Time Total Of 3 Dice Would Be:");            scanf(" %s", &val);        if(val == '0'){            printf("Thanks For Playing!!");            break;        }else{        dice1 = rand()%6 + 1  ;        dice2 = rand()%6 + 1 ;        dice3 = rand()%6 + 1 ;        sum1 = dice1 + dice2 +dice3 ;        printf("----------------------------------------------------\n The dice roll Total is:%d  \n----------------------------------------------------\n " , sum1 );        if(val == 's'  || val == 'l' || val == 'h' ){            if(val=='h' && sum0 < sum1 ){                                            printf("Good Job!! \n");                                            continue;            }else if(val == 'l' && sum0 > sum1){                                            printf("Good Job!! \n");                                            continue;            }else if(val == 's'  && sum0==sum1){                                            printf("Good Job!! \n");                                            continue;            }else{                                            printf("You Suck!!!");                                            continue;            };    }else{                printf("You have to press 'h' or 'l' or 's' \n\n");                continue;    }        }    }while(            val != '\$'           );}

## Replies

- page 1

 Reynaldo Gunawan · June 13, 2015 OMG I feel so stupid. Thank you for your replies osh Ranw · June 3, 2015 if(user = true){            printf("Good Job!\n");        }else{            printf("Meh, you tried!\n");        }    }    ---------------------------------------------------------------------------------------change it to if(user == true){            printf("Good Job!\n");        }else{            printf("Meh, you tried!\n");        }    } c student · June 3, 2015 if(user = true){    /* should be comparison operator here */            printf("Good Job!\n");        }else{            printf("Meh, you tried!\n");        } Reynaldo Gunawan · June 2, 2015 Hey guys, i've been trying to solve this challenge but my program seems to keep insisting that the user has guessed the right thing,  even though it hasn't. Can anyone help me with the code i made? http://textuploader.com/7g9kI would appreciate any related answers to this challenge. Thanks J show · February 14, 2015 Write a program that reads alphanumeric characters from the keyboard, and computes the average ascii value of the alpha numeric characters, the average alphabetical character, the average numeric character and the average uppercase character. Outputting each, you program should terminate reading once it read a non-alphanumeric character. How would you guys go about doing this problem? using ctype.h and isalnum? Lazar Bulic · February 13, 2015 Bravo osh Ranw · February 12, 2015 @ Lazar Bulic Lazar Bulic · February 10, 2015 @c student Thanks  the solution is int c;while ((c = getchar()) != EOF && c != '\n') Ivo Ferro · February 10, 2015 Thanks for all the feedbacks c student · February 10, 2015 @Ivo fflush() is not part of standard c and fflush (stdin) produces undefined behaviour.  don't use it if you can avoid it.@Lazar getchar() returns an int value, therefore in your code, using an unsigned char value may not sufficient enough to handle an EOF return on some systems.
• 1
• 2

## C

129,866 followers