Write a program that can play the “guess the three hidden numbers” game. A numbe
ID: 3766090 • Letter: W
Question
Write a program that can play the “guess the three hidden numbers” game. A number between 0 and 99 is randomly set. Then, the user can specify a “min” and “max”, and the computer has to answer about how many hidden numbers are between the two limits. If the user gives “min=max” then this counts as a GUESS: if the number found is correct, the user gets one point! When all three numbers are found correctly (i.e. user gets three points), then the user wins! His “Number of Turns needed” acts as his score: the smaller, the better.
Useing c languess
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
int num1, num2, num3;
int min, max;
int count = 0, limitCount = 0;
bool found1, found2, found3;
int guess;
// generating 3 hidden numbers
num1 = rand() % 100;
num2 = rand() % 100;
num3 = rand() % 100;
found1 = found2 = found3 = false;
// prompting user to enter guesses
while(1) {
printf("Enter minimum number: ");
scanf("%d", &min);
printf("Enter maximum number: ");
scanf("%d", &max);
if(min == max) {
count++;
if(min == num1) {
found1 = true;
printf("Number 1 found ");
}
if(min == num2) {
found2 = true;
printf("Number 2 found ");
}
if(min == num3) {
found3 = true;
printf("Number 3 found ");
}
}
else {
limitCount = 0;
if(num1 >= min && num1 <= max)limitCount++;
if(num2 >= min && num2 <= max)limitCount++;
if(num3 >= min && num3 <= max)limitCount++;
printf("Number of hidden numbers in between 2 limits: %d ", limitCount);
}
if(found1 && found2 && found3) {
break;
}
}
printf("Numbers of turns needed: %d ", count);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.