# C #Challenge 2 Completed

 Steven vd_W · January 13, 2015 Hey, I made the second challenge, I know it isn't the most compact code but I don't really care about that, and maybe I will make it more compact! I hope you guys/ girls have some tips I can use!  (oh and I'm not english so if you see some spelling/ grammer errors (in the code), I would like to hear that too actually!``#include #include #include #include #include #include int main(){    srand(time(NULL));    int i;    int diceRoll;    int num1, num2, num3, num4, num5, num6, numTog, numTog2; //numTog and numTog2 stands for//numbers Together    char ansFirst[10];    char ansSecond[10];    puts("Hello my friend a dice is going to roll 3 times, you'll get more information further on.");    puts("Enter 'start' if you want to begin with rolling! ");    gets(ansFirst);    if( strcmp(ansFirst, "start") == 0 ) {        for(i=0; i < 3; i++) {            diceRoll = ( rand()%6 ) + 1;            if ( i == 0 ) {                printf("The first number you rolled is: %d \n", diceRoll);                num1 = diceRoll;            }            if ( i == 1 ) {                printf("The second number you rolled is: %d \n", diceRoll);                num2 = diceRoll;            }            if( i == 2 ) {                printf("The third number your rolled is: %d \n", diceRoll);                num3 = diceRoll;            }        }        numTog = num1 + num2 + num3; printf("The numbers together are %d", numTog);        printf("You got one round left, do you think it will be higher/ lower or the same? As the other numbers?: \n");        scanf(" %s", &ansSecond);        for(i=0; i < 3; i++) {            diceRoll = ( rand()%6 ) + 1;            if ( i == 0 ) {            printf("The first number you rolled is: %d \n", diceRoll);            num4 = diceRoll;            }            if ( i == 1 ) {            printf("The second number you rolled is: %d \n", diceRoll);            num5 = diceRoll;            }            if ( i == 2 ) {            printf("The third number you rolled is: %d \n", diceRoll);            num6 = diceRoll;            }            numTog2 = num4 + num5 + num6;        }        if( strcmp(ansSecond, "higher") == 0 && numTog2 > numTog )  {                printf("Good job");        } else if( strcmp(ansSecond, "lower") == 0 && numTog2 < numTog ) {                printf("Good job");        } else if( strcmp(ansSecond, "same") == 0 && numTog2 == numTog ) {                printf("Good job");        } else {            printf("You suck");        }    } else {        printf("Wrong input, sorry try again");    }    return 0;}``

## Replies

 Steven vd_W · January 13, 2015 Omg, I just showed my dad and the code is working well but I really messed up some text :3-----Edit----Maybe I'll fix it so if you don't see something weird I fixed it and edited the post
• 1

## C

118,122 followers