# Code for challenge #2

 David Lush · September 17, 2014 #include #include #include #include #include #include int main(){    srand ( time(NULL) );    int diceA, diceB, diceC;    int diceSum1, diceSum2;    char gameDecider;    char guess;    printf("Type x to exit program\n");    printf("Do you want to play a dice guessing game? (y/n): ");    scanf("%c", &gameDecider);    if(gameDecider == 'y' || gameDecider == 'Y'){                diceA = (rand()%6) + 1;                diceB = (rand()%6) + 1;                diceC = (rand()%6) + 1;                diceSum1 = diceA + diceB + diceC;                printf("The sum of your roll is: %d\n", diceSum1);                printf("Do you think the next roll will be higher or lower? (h/l): ");        do        {            scanf("%c", &guess);            if(guess == 'h' || guess == 'H')            {                diceA = (rand()%6) + 1;                diceB = (rand()%6) + 1;                diceC = (rand()%6) + 1;                diceSum2 = diceA + diceB + diceC;                if(diceSum1 > diceSum2)                {                    puts("\nSorry you were wrong!\n");                    printf("Your second roll was %d\n", diceSum2);                    printf("Type x to exit program\n");                    printf("Do you think the next roll will be higher or lower? (h/l): ");                }                else                {                    puts("\nCongratulations you were right!\n");                    printf("Your second roll was %d\n", diceSum2);                    printf("Type x to exit program\n");                    printf("Do you think the next roll will be higher or lower? (h/l): ");                }            }            else if(guess == 'l' || guess == 'L')            {                if(diceSum1 < diceSum2)                {                    puts("\nSorry you were wrong!\n");                    printf("Your second roll was %d\n", diceSum2);                    printf("Type x to exit program\n");                    printf("Do you think the next roll will be higher or lower? (h/l): ");                }                else                {                    puts("\nCongratulations you were right!\n");                    printf("Your second roll was %d\n", diceSum2);                    printf("Type x to exit program\n");                    printf("Do you think the next roll will be higher or lower? (h/l): ");                }           }           else if(guess == 'x'){                return 0;           }        }while(1);    }    return 0;}

## Replies

Nothing to see here.

## C

129,997 followers