Answer:
Check the explanation
Step-by-step explanation:
Code:
#include <stdio.h>
int ask_in_range(int min, int max)
{
int n;
printf("Please guess a number: ");
scanf("%d", &n);
while(n<min || n>max)
{
printf("Your number is outside of [-100, 100] range. Please enter a number: ");
scanf("%d", &n);
}
return n;
}
int guessing_game(int num, int rangemin, int rangemax)
{
printf("Hello and welcome to the game.\\");
printf("You need to guess a number between -100 and 100.\\");
int count = 1;
int guess = ask_in_range(rangemin, rangemax);
while(guess!=num)
{
if(guess<num)
printf("Too low!\\");
else
printf("Too high!\\");
guess = ask_in_range(rangemin, rangemax);
count++;
}
printf("Good job! You took %d guesses.\\", count);
return count;
}
int main()
{
int count = guessing_game(13, -100, 100);
return 0;
}
Kindly check the attached images below to see the CODE SCREENSHOT and CODE OUTPUT.