# Challenge 2!!

 Ossama Memon · December 24, 2015 #include #include #include int main(){    int sum = 0;    int sum1 = 0;    char g;    int i;    int j;    int dice;    int a;    printf("Press 1 to enter the game\n");    scanf(" %d", &a);    if(a == 1){        for(i=0; i; i++){        dice = (rand()%6) + 1;        printf("Random numbers are %d \n",dice);        sum += dice;    }    printf("The sum of three rolls is %d\n", sum);    for(j=0; j; j++){        dice = (rand()%6) + 1;        printf("Random numbers are %d \n", dice);        sum1 += dice;    }    printf("Guess if upper, lower or same. (U/L/S) \n");    scanf(" %c", &g);    if(sum1 < sum){        if(g == 'U'){            printf("You guessed right..\n");        }else{            printf("Loser!!");        }        if(sum1 > sum){            if(g = 'L'){                printf("You guessed right..\n");            }else{                printf("Loser!!");            }            if(sum1 == sum){                if(g == 'S'){                    printf("You guessed right..\n");                }else{                    printf("Loser!!");                }            }        }    }    }    return 0;}

## Replies

 Linguist Llama · December 27, 2015 What have you noticed about the sequence of numbers that your program generates when you run it time and time again? Ossama Memon · December 28, 2015 Linguist Llama I noticed that the random numbers are just 5 and 6  ok. How to resolve this problem? Laura Lee · December 28, 2015 You will have to seed the random. In your case, using the srand function. Linguist Llama · December 28, 2015 Go back through the video and see what you have missed... Ossama Memon · December 29, 2015 Alright. First let me use srand function and if nothing happens then I've to see the video again. Thanks Linguist Llama for pointing out my mistake and thanks Laura as well. Ossama Memon · December 29, 2015 Ok. Sorry for the noob question Laura but how to use srand function ? Llama I've watched the whole video again but looks like I haven't missed anything. Linguist Llama · December 30, 2015 Let's try another approach... Have you tried googling "How do I use srand"? Or would you like us to google for you? Ossama Memon · December 30, 2015 Linguist Llama I googled it before your reply to know how actually srand works. But I couldn't understand it's syntax. What is time used for in srand?
• 1

## C

129,958 followers