dice roll

0 Dhawal S · February 14, 2015
hmm this is the code i hav written check it out

void main()
{
 int a,b=1;
 char c;
 r:
 printf("Enter your option to roll dice(y/n)\t");
 while(b>0)
 {
  scanf("%c",&c);
  if(c=='y')
  {
   a=rand()%6+1;
   if(a==6)
   {
    printf("\nYour are lucky you got %d\n",a);
    goto r;
   }
   else
   {
    printf("\nBetter luck next time. you got %d\n",a);
    goto r;
   }
   b++;
  }
  if(c=='n')
  {
   printf("Okay then bye-bye");
   b=-1;
  }
 }
}

itz a bit lengthy but accurate




Post a Reply

Replies

Oldest  Newest  Rating
0 Lazar Bulic · February 14, 2015
/images/forum/upload/2015-02-14/0229ec4cf5a6296e3c2956a6fe937273.PNG

Can it be a little more random?

Also what happens when I input something else than y or n? Maybe add that part.

What if I enter 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'???? 
0 Tomislav Keškić · February 14, 2015
he needs to add srand(time(0)); function
0 Dhawal S · February 15, 2015
i dont know how to do tat can u jus tell me  # Lazar Bulic
0 Lazar Bulic · February 15, 2015
IF you want to get the code to run more randomly here is an example: 
http://stackoverflow.com/questions/16569239/how-to-use-function-srand-with-time-h
0 Dhawal S · February 15, 2015
thankz
  • 1

C

107,302 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator