1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
goldenfox [79]
3 years ago
6

Write a program with a method that plays the guess a number game. The program should allow the user to pick a number between 1 a

nd 1000 in his head. The method should guess the user's number in a minimal amount of attempts. The method should ask the user "is the number greater than or less than the number " and the program gives a particular number. The user in some way just inputs (higher or lower) or (greater than or less than). There also has to be a way for the user to say the number has just been guessed. Of course, the user cannot answer incorrectly or change the number midstream. Note - if written efficiently, the method should be able to guess any number in 10 or less attempts.
Computers and Technology
1 answer:
nlexa [21]3 years ago
8 0

Answer:

Please check the explanation

Explanation:

That's the code and it is done with the program in c++ according to instructions given in the question using binary search. It can guess the correct number in 10 or fewer attempts and also shows the number of attempts it took to guess the number.

​ #include <iostream> using namespace std; int guess() { string input; int l = 1, h = 1000; int mid = (l + h) / 2, count = 0; while (1) { //count the number of attemts to guess the number ++count; //cout << count << "\n"; cout << "\n"; cout << "Is " << mid << " correct? (y/n): "; cin >> input; //if input is y print the guessed no. and return if (input == "y") { cout << mid << " guessed in " << count << " attempts!\n"; return 1; } //if input is n ask the user if it's higher or lower than current guess if (input == "n") { cout << "Is the number greater than or less than the number ? (h/l): "; cin >> input; } //if input is higher assign mid incremented by 1 to low //else decrement mid by 1 and assign to high if (input == "h") l = mid + 1; else h = mid - 1; //calculate mid again according to input by user again mid = (l + h) / 2; } } int main() { cout << "****WELCOME TO THE GUESS THE NUMBER GAME!****\n"; cout << "Guess any number between 1 to 1000.\n"; cout << "This game depends on user giving correct answers and not changing their number middle of game.\n"; guess(); } ​

You might be interested in
What are the positive impact of computer in society
Brrunno [24]

Answer:

we can communicate many peoples

8 0
3 years ago
How do economists use data? check all that apply
Stella [2.4K]

Economists use data:

  • To explain trends in production and shipping.
  • To follow and predict unemployment rates.

<h3>How do economists make predictions?</h3>

Economists  often uses data to make forecast and it is where there is the use of sample data from a population that brings about uncertainty.

Note that Economists use data:

  • To explain trends in production and shipping.
  • To follow and predict unemployment rates.

See options below

How do economists use data? Check all that apply.

to follow and predict unemployment rates

to communicate with customers instantly

to ship goods to countries all over the world

to explain trends in production and shipping

to apply automation to reduce production costs

Learn more about economists from

brainly.com/question/9913581#SPJ12

3 0
3 years ago
After a failover cluster is created, which of the following is a task to be performed when configuring the failover cluster? (Ch
Lynna [10]

Answer: (B) Configure the cluster networks

               (C) Configure the quorum model

Explanation:

 When the fail-over cluster has been created then, configure the cluster network and quorum model tasks performed during configuring the fail-over cluster.

The quorum model are flexible in the window server. We can configure the quorum model when we need to modified the quorum model configuration for the cluster. The software cluster are automatically configure quorum model for the new cluster that is based on the availability of the share storage.

When configuring the fail-over cluster we can perform various cluster network tasks in the system.  

 

 

 

8 0
3 years ago
In this assignment, you will need to design a complete Black-Box testing plan for the following program. A computer science stud
murzikaleks [220]

Answer: sorry i need points to ask a question hope u understand...

Explanation:

8 0
3 years ago
A(n) ______of the audio or video clip makes the content easily accessible to people with hearing disabilities.
defon

subtitles

hope that helped you

7 0
4 years ago
Read 2 more answers
Other questions:
  • Alice has to move around a lot to fetch objects at her workstation. Which ergonomic principle should Alice follow to prevent str
    8·2 answers
  • Chances are if you ar Chances are, if you are involved in a crash, it will happen __________ a. during a long trip. b. close to
    7·2 answers
  • To what extent do you think st. cyprian was effective in his efforts to bring inherited christian teachings to bear on the unpre
    10·1 answer
  • Universal Containers (UC) is currently live with Sales Cloud and in the process of implementing Service Cloud. UC wants to creat
    5·1 answer
  • Information security is defined as practice of preventing unauthorized access, use, disclosure, disruption, modification, or ___
    6·1 answer
  • Why are listening and speaking part of the Common Core and ELD Standards? Why is this particularly important for our ELD student
    14·1 answer
  • _______ imaging technology defines locations in the brain where neurons are especially active using safe radioactive isotopes to
    8·2 answers
  • Jennifer has to set up a network in a factory with an environment that has a lot of electrical interference. Which cable would s
    14·1 answer
  • How are special characters added to a Word document? Check all that apply.
    11·2 answers
  • Deirdre has a hearing disability. One of her friends advised her to use real-time text or RTT on her phone. In which of these
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!