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 charts the cost to the company of the unavailability of information and technology and the cost to the company of recoverin
Gala2k [10]

Answer:

D. Disaster recovery cost curve

Explanation:

Disaster Recovery Cost Curve can be regarded as the chart to the cost of the

unavailability of information and technology as well as the the cost to the company of recovering from a disaster over time. It should be noted that recovery plan is very essential in any organization because it makes response to disaster as well as other emergency that can tamper with information system to be easier as well as minimization of any effect of the disaster on business operations.

6 0
3 years ago
You are required to justify the need to implement a three-tier campus network. Which justification below makes sense for a three
Murrr4er [49]

Answer:

Correct answer is (d) Scalable solution for an enterprise environment

Explanation:

Scaling and enterprise simply means adding up resources to the business need. By adding hardware (s) or by upgrading the existing hardware without changing much of the application, one will be able to implement a three-tier campus network.

8 0
3 years ago
Which categories format cells
fredd [130]
Currency, percentage, date, time, fraction, scientific
4 0
3 years ago
Read 2 more answers
Which of the following is true of Shareable Content Object Reference Model (SCORM)? Group of answer choices guidelines that allo
dalvyx [7]

Answer:

The correct answer to the following question will be Option B (Control how well the e-learning artifacts interact technically with LMS).

Explanation:

SCORM seems to be a compilation of requirements and criteria for commodities used during e-learning. This describes the different ways to communicate here between information or data on the customer side as well as the run-time context.

  • The specification also specifies how to bundle e-learning material for functionality, this is achieved by using the Bundle Exchange Format, an exchangeable ZIP file.
  • It is essentially a manual that informs developers as well as content providers on how to make their apps or programs compliant with several other e-learning apps including applications.

The other three options are not related to the given scenario. So that option B is the right answer.

6 0
3 years ago
Computer virus is a<br> a. software<br> b. hardware<br> c. bacteria<br> d. none of these
Nimfa-mama [501]
The answer is software
8 0
4 years ago
Other questions:
  • A company that wants to send data over the Internet has asked you to write a program that will encrypt it so that it may be tran
    6·1 answer
  • Gina is upgrading your computer with a new processor. She installs the processor into your motherboard and adds the cooling syst
    13·2 answers
  • 5. What must be included in Turtle Graphics to move the Turtle around the screen?
    7·1 answer
  • How is a technical certificate like a computer-related associate degree?
    12·2 answers
  • What was the first e-commerce service?
    10·1 answer
  • The following are types of numbers except one. Select the one which is not an integer.
    11·1 answer
  • A source is:
    15·2 answers
  • What is versatility according to computer​
    11·1 answer
  • Queries in Access can be used ______________
    9·1 answer
  • - Discuss the input-process-output model as it relates to program development.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!