// Guess the number
// V1.1 by Steve with a little help from Russ
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void main()
{
int guesses = 0;
int guess = 0;
srand(time(NULL));
int number = rand() % 256;
printf("Guess the number\n");
while (guess != number)
{
scanf("%d", &guess);
if (guess > number)
printf("Lower!\n");
else if (guess < number)
printf("higher\n");
printf("Try again!\n\n");
guesses++;
}
printf("Correct! You got it in %d guesses\n", guesses);
getchar();
}
Comments