my two cents
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main() {
int RandomNumber, Guess;
time_t RandomSeeder;
srand((unsigned) time(&RandomSeeder));
// RandomNumber = rand() % 100;
RandomNumber = 50;
printf("Enter a guess, please: ");
scanf("%d", &Guess);
while(Guess > RandomNumber || Guess < RandomNumber)
{
if(Guess > RandomNumber)
printf("Too high!\n");
else // it's either one or the other yes?
// if(Guess < RandomNumber)
printf("Too low!\n");
printf("Try again: ");
// gets the value here so it does not go though the if statements frist
// but the conditional check first. so if match it kicks it out of loop.
// so no real need to worry about if statements for everything. if else suffices.
// if you'd put that scanf on top before the if stameants then that'd be a different story.
scanf("%d", &Guess);
}
if(Guess == RandomNumber)
printf("You win!\n");
return 0;
}
just gave it a hard coded value to check it.
Code:
$ ./term2
Enter a guess, please: 49
Too low!
Try again: 51
Too high!
Try again: 50
You win!