Initial commit
This commit is contained in:
@@ -0,0 +1,10 @@
|
|||||||
|
#include "guesser.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int guess_number(int min, int max)
|
||||||
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
return rand() % max + min;
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "guesser.h"
|
||||||
|
|
||||||
|
#define MAX_TRIES 10
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
printf("Guess the number between 1 and 100:\n");
|
||||||
|
|
||||||
|
int number = guess_number(1, 100);
|
||||||
|
|
||||||
|
int user_guess;
|
||||||
|
int tries = 0;
|
||||||
|
|
||||||
|
do
|
||||||
|
{
|
||||||
|
printf("%d tries left. Guess: ", MAX_TRIES - tries);
|
||||||
|
scanf("%d", &user_guess);
|
||||||
|
|
||||||
|
if (abs(user_guess - number) < 10)
|
||||||
|
{
|
||||||
|
printf("You're close\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user_guess > number)
|
||||||
|
{
|
||||||
|
printf("A bit lower\n");
|
||||||
|
tries++;
|
||||||
|
}
|
||||||
|
else if (user_guess < number)
|
||||||
|
{
|
||||||
|
printf("A bit highter\n");
|
||||||
|
tries++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
while (number != user_guess && tries < MAX_TRIES);
|
||||||
|
|
||||||
|
if (tries == MAX_TRIES)
|
||||||
|
{
|
||||||
|
printf("You lost :(\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("You won! Good job :)\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user