can you tell me why this is crashing?

0 nick mays · October 23, 2015
//Dice Game...

int main(){

    int loop;
    int dice1;
    int dice2;
    int dice3;
    int dice4;
    int guess1;
    int guess2;
    int guess3;
    char finalGuess;
    int total;

    printf("1st Guess:");
    scanf(" %d\n", guess1);

    for(loop==0; loop<=1; loop++){
            dice1 = ( rand()%6 + 1);
            printf("%d\n", dice1);

    printf("2nd Guess:");
    scanf(" %d\n", guess2);

    for(loop=0; loop<=1; loop++){
            dice2 = ( rand()%6 + 1);
            printf("%d\n", dice2);


    printf("3rd Guess:");
    scanf(" %d\n", guess3);

     for(loop=0; loop<=1; loop++){
            dice3 = ( rand()%6 + 1);
    printf("%d\n", dice3);

    total = (dice1+dice2+dice3);

    printf("Here is your Total: %d\n", total);
    printf("Guess if this one will be (h/l) than last: ");
    scanf("%d\n", finalGuess);

      for(loop=0; loop<=1; loop++){
            dice4 = ( rand()%6 + 1);
    printf("%d\n", dice4);

    if( (finalGuess == 'h')||(finalGuess>dice4) ){
        printf("Good Job.\n");

    }else if( (finalGuess == 'l')||(finalGuess<dice4) ){
        printf("Good Job.\n");

        printf("You Suck!");




Post a Reply


Oldest  Newest  Rating
0 Cristiano Cappagli · October 23, 2015
Well, first it crashes because when you use scanf() instead of

scanf(" %d", guess1);

you have to write:
scanf(" %d", &guess1);

Then i don't understand so much your for loops ;) and the first has a == instead of =
Try to run again and rewrite it :D
  • 1



One of the most popular languages of all time.

Bucky Roberts Administrator