#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <process.h>
#include <string.h>
void main()
{
int i, n, diff;
int x = rand() % 100;
int bMoveHigher = 0;
int bGuessedCorrectly = 0;
printf("Welcome to Guess a Word Program\n");
for (i = 1; i <= 5; i++)
{
printf("ATTEMPT %d: Enter the your number: ", i);
scanf("%d", &n);
if (n == x)
{
printf("Congrats! You have guessed the number correctly\n");
bGuessedCorrectly = 1;
break;
}
diff = (int)(fabs(x - n));
if(x > n)
bMoveHigher = 1;
if(diff >= 50)
{
if (bMoveHigher == 0)
printf("Your guess is VERY HIGH\n");
else
printf("Your guess is VERY LOW\n");
}
else if (diff >= 30)
{
if (bMoveHigher == 0)
printf("Your guess is HIGH\n");
else
printf("Your guess is LOW\n");
}
else if (diff >= 15)
{
if (bMoveHigher == 0)
printf("Your guess is MODERATELY HIGH\n");
else
printf("Your guess is MODERATELY LOW\n");
}
else
{
if (bMoveHigher == 0)
printf("Your guess is SOMEWHAT HIGH\n");
else
printf("Your guess is SOMEWHAT LOW\n");
}
}
if (bGuessedCorrectly == 0)
{
printf("Unfortunately you did not guess it correctly. The correct number is: %d\n", x);
}
}
Inline Code Example Here