need help for dice number exercise----C programming

0 alex he · March 5, 2015
Every time I guess my dice number, my dice number is always 6. Why don't my dice number change randomly????





#include <stdio.h>
#include <stdlib.h>


int main()
{
int i = 0;
int dicenumber;
int guess;

dicenumber = (rand()%6)+1;


do{
printf("guess a number(1-6)\n");
scanf(" %d", &guess);

if(guess == dicenumber){
printf("time: %d congratulations\n",i);
}
if(guess < dicenumber){
printf("time: %d too low\n",i);
}
if(guess > dicenumber){
printf("time: %d too high\n",i);
}
i++;
}while(guess != dicenumber);



return 0;
}

Post a Reply

Replies

Oldest  Newest  Rating
0 OLayemii Garuba · March 16, 2015
because you're not seeding your random number include <ctime>, then type in srand(time(NULL)); before the rand
  • 1

C

107,290 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator