Challenge/Assignment given by Bucky on the 38th episode (random number generation) of C

0 Dona Paul · October 4, 2015
Guyz i cant get what Bucky said. The program generates 3 random numbers for rolling of a dice, and calculate the sum. Upto that its fine.  Now the user have to guess that the next roll is gonna be higher, lower, or same.... than what ? the sum?or than the last(3rd) roll ? 

Post a Reply

Replies

Oldest  Newest  Rating
0 abhijeet Sharma · October 6, 2015
#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<assert.h>
#include<math.h>
#include<time.h>

int main()
{
    int dicenumber;
    int n,sum,sum1;
    int a[4];
    char ans;
srand(time(NULL));
         printf("\nthe numbers are :");
    for(n=0;n<3;n++){
            dicenumber = rand()%6+1;
            printf("\n %d",dicenumber);
            a[n]=dicenumber;
            }
            sum = a[0]+a[1]+a[2];

            printf("\nthe sum of dicenumber is: %d\n",sum);

            printf("what is your choice  i.e the sum would be greater then this %d?(y/n)\n)",sum);
            scanf(" %c",&ans);

                 srand(time(NULL));
                for(n=0;n<3;n++)
                    {
                    dicenumber = rand()%6+1;
                    a[n]=dicenumber;
                    }
                 sum1 = a[0]+a[1]+a[2];
                 if ((sum1>sum&&ans=='y')||(sum1<sum&&ans=='n'))
                 {
                     printf("you won");
                 }
                 else
                 {
                    printf("youlose");
                 }
              printf("%d",sum1);
    return 0;
}
0 Dona Paul · October 13, 2015
yeah thanx :)
  • 1

C

107,087 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator