Answer:
Check the explanation
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.\n");
printf("You need to guess a number between -100 and 100.\n");
Â
int count = 1;
int guess = ask_in_range(rangemin, rangemax);
Â
while(guess!=num)
{
if(guess<num)
printf("Too low!\n");
else
printf("Too high!\n");
Â
guess = ask_in_range(rangemin, rangemax);
count++;
}
Â
printf("Good job! You took %d guesses.\n", 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.