1. ## Three Dice Roll

Question : Create a game using C wherein user rolls 3 dices and it prints out the total on them-dice a+dice b+dice c.Now after the user looks at the no. they would guess if the next roll will be higher(type H if it is) ,lower(type L for that) and if it is same(S for that). Then they gonna roll it again and if the guess is right print out "Good Job" and if wrong then "You suck" or something like that.

My Solution:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

int main()
{
int a,b,c,x;
char guess;

x= rand()%6 + rand()%6 + rand()%6 +3;
printf("The sum of the nos. on three dices is %d\n",x);

a= rand()%6 +1;
b= rand()%6 +1;
c= rand()%6 +1;
printf("Guess the next no.will be higher,lower or same(H/L/S):");
scanf(" %s",&guess);
printf("%d\n",a+b+c);
switch(guess){
case 'L' : ((a+b+c) < x) ? printf("\nGood Job") : printf("You Suck");
break;
case 'S' : ((a+b+c) == x) ? printf("\nGood Job") : printf("You Suck");
break;
case 'H' : ((a+b+c) > x) ? printf("\nGood Job") : printf("You Suck");
break;
default : printf("Sorry");
}

return 0;
}

Please do tell me if it is correct or anything that can be made better.
Thanks.

Code:
```    a= rand()%6 +1;
b= rand()%6 +1;
c= rand()%6 +1;```
why don't you write something similar to line 10... maybe

Code:
`y= rand()%6 + rand()%6 + rand()%6 +3;`
And then change all your conditionals in the switch to y < x etc instead of a+b+c

I'd use better variable names than x and y, though.

You haven't seeded the pseudo random number generator so the sequence of random numbers is going to be the same every time you run the program. Google for srand and call it once at the start of your program.

Code:
`scanf(" %s",&guess);`
^-- Did you intend this to be %s? If the user enters more than 1 character your program is likely to crash or be naughty in other ways

I wouldn't hardcode the value of 6. I'd have something along the lines of
Code:
`#define DICE_NUM_SIDES 6`
and then

Code:
`x= rand()%DICE_NUM_SIDES + rand()%DICE_NUM_SIDES + rand()%DICE_NUM_SIDES +3;`
etc

Makes the code longer, but it's more readable and easier to maintain if someone decides they want the game to use dice with 20 sides each

3. because i enjoy coding random stuff...

Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define DICECOUNT 3
#define DICESIDES 6
#define SUCCESS "CORRECT."
#define FAILURE "FAIL."

int a, b, c, x, y; char guess;

int roll() {
return (rand() % (DICESIDES - 1 + 1)) + 1;
};

int rollDice(int diceAmount) {
int xx = 0;
for (int i=0; i < diceAmount; i++) {
xx += roll();
};
return xx;
};

int main() {
srand(time(0));

x = rollDice(DICECOUNT);
y = rollDice(DICECOUNT);

printf("NUMBER: %d\n", x);
printf("[h]igher, [l]ower or [s]ame ?");
scanf("%s",&guess);
printf("NUMBER: %d\n", y);

switch(guess) {
case 's':
if (x == y) {
printf("%s",SUCCESS);
} else {
printf("%s",FAILURE);
}
break;
case 'h':
if (y > x) {
printf("%s",SUCCESS);
} else {
printf("%s",FAILURE);
};
break;
case 'l':
if (x > y) {
printf("%s",SUCCESS);
} else {
printf("%s",FAILURE);
};
break;
};

return 0;
};```