Dice challenge is not working properly.

0 Andrew Smith · September 16, 2015
When playing the program it will not get passed the first if else why is that? 


#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <math.h>


int main(int argc, char *argv[])
{
int i;
int j;
int diceRoll1;
int diceRoll2;
int diceRoll3;
int totalNumber1;
int totalNumber2;
char guess;


srand (time(NULL));


    for(i=0; i<1; i++){
        diceRoll1 = ( rand()%6 ) +1;
        printf("Dice roll one is %d \n", diceRoll1);
        }
    for(i=0; i<1; i++){
        diceRoll2 = ( rand()%6 ) +1;
        printf("Dice roll two is %d \n", diceRoll2);
        }


    for(i=0; i<1; i++){
        diceRoll3 = ( rand()%6 ) +1;
        printf("Dice roll three is %d \n", diceRoll3);
        }


    totalNumber1 = diceRoll1 + diceRoll2 + diceRoll3;
    printf("your total roll is %d \n\n\n", totalNumber1);


    printf("Do you think your next roll will be higher, lower, or the same?\n");
    printf("Type h for higher, l for lower, and s for same.\n");
        scanf("%c", &guess);


srand (time(NULL));


    for(j=0; j<1; j++){
        diceRoll1 = ( rand()%6 ) +1;
        printf("Dice roll one is %d \n", diceRoll1);
        }
    for(j=0; j<1; j++){
        diceRoll2 = ( rand()%6 ) +1;
        printf("Dice roll two is %d \n", diceRoll2);
        }


    for(j=0; j<1; j++){
        diceRoll3 = ( rand()%6 ) +1;
        printf("Dice roll three is %d \n", diceRoll3);
        }


    totalNumber2 = diceRoll1 + diceRoll2 + diceRoll3;
    printf("your total roll is %d \n\n\n", totalNumber2);






if(guess == 'h' || 'H') {
    if(totalNumber2 > totalNumber1){
        printf("you are correct!");
    }else{
            printf("you were incorect..");
    }


}else if(guess == 'l' || 'L') {
    if(totalNumber2 < totalNumber1){
        printf("you are correct!");
    }else{
            printf("you were incorect..");
    }


}else if(guess == 's' || 's') {
    if(totalNumber2 == totalNumber1){
        printf("you are correct!");
    }else{
            printf("you were incorect..");
    }


}


    return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
+2 Jon Z. · September 16, 2015

if(guess == 'h' || guess == 'H')
0 Andrew Smith · September 17, 2015
Thank you!
  • 1

C

106,929 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator