"
Number Guessing Game
You should think of a number between 1 and 100. Then, over and over again, the computer can suggest an answer. Your response to the computer guess will be as following:
Requirements:
Hints:
Have fun!
"
Here is what I have so far:
/*
Input: <, >, and =.
Output: Number.
Description: This code will guess your number in 7 moves or
less.
Language: C
*/
#include <stdlib.h>
#include <stdio.h>
void main(void)
{
int mid = 50;
int max = 100;
int min = 1;
char ans;
char small = '>';
char large = '<';
char right = '=';
int i = 0;
printf("Choose a number between 1 to 100. I can guess your
number in 7 moves or less\n");
printf("Is your number 50?\n");
printf("[>] If answer is too small.\n");
printf("[<] If answer is too large.\n");
printf("[=] If answer is just right.\n");
scanf(" %c", &ans);
while(ans != right)
{
if(ans == large)
{
printf(" Is your number %d?\n", mid/2);
max = mid + 1;
mid = (min+max)/2;
scanf(" %c", &ans);
i++;
}
if(ans == small)
{
printf(" Is your number %d?\n", (mid + max)/2);
min = mid - 1;
mid = (mid + max)/2;
scanf(" %c", &ans);
i++;
}
}
if(ans == right)
{
printf("Yay! I choose your answer in %d moves\n", i);
exit(0);
}
}
-------------------------------------------------
Currently, it works if the number is less than 50 but breaks
when the number is higher than 50. I am pretty sure the math part
is wrong but I don't know how to fix it.
CODE:-
#include <stdlib.h>
#include <stdio.h>
void main(void)
{
int mid = 50;
int max = 100;
int min = 1;
char ans;
char small = '>';
char large = '<';
char right = '=';
int i = 1;/*here it must be 1 because suppose number guessed was
actually 50 then
it shows that number of moves was 0 which is incorrect because it
does have make a move
by comparing guessed number to 50*/
printf("Choose a number between 1 to 100. I can guess your
number in 7 moves or less\n");
printf("Is your number 50?\n");
printf("[>] If answer is too small.\n");
printf("[<] If answer is too large.\n");
printf("[=] If answer is just right.\n");
scanf(" %c", &ans);
while(ans != right)
{
if(ans == large)
{
max = mid-1;/* here first we need to change max value as mid is too
large
so , we need to change max to number immediate smaller than
mid*/
mid = (max+min)/2;/*now, change mid according to new max value
.
add max and min and divide it by 2 and then take its floor
value*/
printf(" Is your number %d?\n", mid);
scanf(" %c", &ans);
i++;
}
if(ans == small)
{
min = mid+1;/* here first we need to change min value as mid is too
small
so , we need to change min to number immediate bigger than
mid*/
mid = (min+max)/2;/*now, change mid according to new max value
.
add max and min and divide it by 2 and then take its floor
value*/
printf(" Is your number %d?\n", mid);
scanf(" %c", &ans);
i++;
}
}
if(ans == right)
{
printf("Yay! I choose your answer in %d moves\n", i);
exit(0);
}
}
output:-
When guessed number is larger than 50
when
guessed number is smaller than 50
CODE
screenshot:-


" Number Guessing Game You should think of a number between 1 and 100. Then, over...
Write a number guessing program in C. You think of a number between 1 and 100 and the computer keeps suggesting answers, where in case the answer is too small, you enter the character >. If the computer's answer is too large, you enter the character <. And if the computer's answer is just right, you enter =
please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file. (on separate lines) Write the number of guesses to the file at the end of the game. After the game is finished, ask the user if they want to play again. If 'n' or 'N' don't play again, otherwise play again! NOTE: your file should have more than one game in it if the user...
Number Guessing Game Games Write program in C++. For this game, the computer will select a random number between 1 and 100 (inclusive). The computer will then ask the (human) player to guess the number the computer has selected. After the player’s guess is input to the computer, the computer will output one of three responses, depending on the relationship of the number the player guessed to the number the computer selected: “Your guess was too low.” “Your guess was...
Java Listed below is code to play a guessing game. In the game, two players attempt to guess a number. Your task is to extend the program with objects that represent either a human player or a computer player. boolean checkForWin (int guess, int answer) { System.out.println("You guessed" + guess +"."); if (answer == guess) { System.out.println( "You're right! You win!") ; return true; } else if (answer < guess) System.out.println ("Your guess is too high.") ; else System.out.println ("Your...
In Java You’re going to make a Guess the Number game. The computer will "think" of a secret number from 1 to 20 and ask the user to guess it. After each guess, the computer will tell the user whether the number is too high or too low. The user wins if they can guess the number within six tries. The program should look like this in the console, player input is in bold: Hello! What is your name? Abaddon...
Make a FLOWCHART for the following JAVA Prime Number Guessing Game. import java.util.Random; import java.util.Scanner; public class Project2 { //Creating an random class object static Random r = new Random(); public static void main(String[] args) { char compAns,userAns,ans; int cntUser=0,cntComp=0; /* * Creating an Scanner class object which is used to get the inputs * entered by the user */ Scanner sc = new Scanner(System.in); System.out.println("*************************************"); System.out.println("Prime Number Guessing Game"); System.out.println("Y = Yes , N = No...
python code for guessing game users enter the number the computer
will guess
8:38 PM 100 nstructure.com 1. Number guessing game : (5 points) 1) Requirements: Your program will ask the user to enter a number between 1 and 1000. Then it will try to guess the correct number with the guaranteed minimal average number of guesses. Which search algorithm should you use? 2) Expected Output: Enter a number between 1 and 1000? 784 Computer guesses: 500 Type 'l' if...
Guess My Number Create a mul5-func5on version of the Guess My Number game. Your game should generate a random number between 1 and 99, ask the user for a guess, and respond to each guess with correct, too high, or too low as needed. Once the user guesses the number correctly, report how many guesses it took and ask if they want to play again. You need to have at least the following three func5ons: displayInstruc5ons — no inputs, displays...
Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...
Need help with this C program? I cannot get it to compile. I have to use Microsoft Studio compiler for my course. It's a word game style program and I can't figure out where the issue is. \* Program *\ // Michael Paul Laessig, 07 / 17 / 2019. /*COP2220 Second Large Program (LargeProg2.c).*/ #define _CRT_SECURE_NO_DEPRECATE //Include the following libraries in the preprocessor directives: stdio.h, string.h, ctype.h #include <stdio.h> /*printf, scanf definitions*/ #include <string.h> /*stings definitions*/ #include <ctype.h> /*toupper, tolower...