challenge 2 help

+2 Suraj Gautam · June 5, 2015
I asked for help in my previous post but no one helped me. The program runs nicely and there is no error but I didnt get desired output. Please have a look

#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int i, diceA,diceB, diceC,diceD,diceE,diceF,Total,Total2;
char guess;
printf("You rolled 3 dice and the result is: \n\n");
for(i=0;i<5;i++)
{
    diceA=(srand()% 6)+ 1;
    diceB=(srand()% 6)+ 1;
    diceC=(srand()% 6)+ 1;
}
printf("The result of dice A is: % d\n",diceA);
printf("The result of dice B is: % d\n",diceB);
printf("The result of dice C is: % d\n",diceC);
 Total= diceA+diceB+diceC;
printf("The total obtained in this round is % d\n\n",Total);

printf("The next dice is going to be rolled\n\n");

printf("Can you guess the next roll? \n\n");
printf("Will it be higher, lower or same? \n\n");

    diceD=(rand()% 6)+ 1;
    diceE=(rand()% 6)+ 1;
    diceF=(rand()% 6)+ 1;
Total2= diceC+diceD+diceE;
printf("Enter h for higher, l for lower and s for same ^_^\n\n");
scanf("% c",guess);

printf("The result of dice A is: % d\n",diceD);
printf("The result of dice B is: % d\n",diceE);
printf("The result of dice C is: % d\n",diceF);

printf("The total of this round  is % d\n",Total2);

if ((Total2 > Total) && (guess == 'h')) {
printf("Good Job\n\n");
}
else if ((Total2==Total) && (guess=='s'))
{
    printf("Good Job\n\n");
}
else if ((Total2 < Total) && (guess=='l'))
{
    printf("Good Job\n\n");
}
else
{
    printf("You suck");
}
return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 K D · June 9, 2015
um you actually have a lot of errors...

ok so first one is there should be a space right after #include  and also conio.h is strictly windows.  The main function/method must be of return type int not void unless using a non standard compiler which i don't suggest you do...

diceA=(srand()% 6)+ 1;
diceB=(srand()% 6)+ 1;
diceC=(srand()% 6)+ 1;
srand() does not return a random number it seeds the number generator so i would suggest not using it here..  I would include time.h and put srand(time(NULL)); at the top of main so change those srand()s to rand()


Don't put a space between %d or %c or any others.  for scanf you need a '&' before variable name unless its a string for example:
scanf("%c", &guess);

if you want to worry about conserving memory i would try to cut down on number of variables used...

btw i think you need to include stdlib.h for srand and rand but i am not sure.

I really hope this helps...
0 Suraj Gautam · June 10, 2015
Thank you. I will try to debug the error :)
  • 1

C

107,073 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator