# guess the number game

I'm making a little game where the program chooses a random number, and then you have ti input a number to see if you got the answer wrong or right. heres the code i have so far:

#include

int main(void)
{
int num, actualvalue, i;

printf("This is a small game called Guess The Number.
You have 10 tried to guess the magic number.
");

for(i=1; i<11 && num != actualvalue; i++)
{
printf("Guess a number: ");
scanf("%d", &num);

if(num<actualvalue) printf("The number you have inputed is lower than the magic number. Try again.
");
if(num>actualvalue) printf("The number you have inputed is higher than the magic number. Try again.
");
if(num==actualvalue) printf("RIGHT!");
}

system("PAUSE");
return 0;
}

the part i dont understand is how can i make the computer generate a number from 1-250? thx in advance

• : I'm making a little game where the program chooses a random number, and then you have ti input a number to see if you got the answer wrong or right. heres the code i have so far:
:
: #include
:
: int main(void)
: {
: int num, actualvalue, i;
:
: printf("This is a small game called Guess The Number.
You have 10 tried to guess the magic number.
");
:
:
: for(i=1; i<11 && num != actualvalue; i++)
: {
: printf("Guess a number: ");
: scanf("%d", &num);
:
: if(num<actualvalue) printf("The number you have inputed is lower than the magic number. Try again.
");
: if(num>actualvalue) printf("The number you have inputed is higher than the magic number. Try again.
");
: if(num==actualvalue) printf("RIGHT!");
: }
:
: system("PAUSE");
: return 0;
: }
:
: the part i dont understand is how can i make the computer generate a number from 1-250? thx in advance
:
To generate a random number between 1 and 250,you may use this:
[code]#include
#include

...
srand(time(NULL)); /*to initialize the random generator*/
random_value=rand()%250+1;[/code]

Take care, Steph.