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 laptop is the best for programming and hacking​
Archy [21]

Answer:

I would suggest an outdated laptop that can't be updated anymore because it is old and outdated.

Explanation:

If you hack on an old laptop it can't be traced back to you because the servers are shutdown.

3 0
3 years ago
List at least 4 types of works covered by copyright law
Shtirlitz [24]

Answer:

musical works, dramatic works, literary works, sound recordings.

6 0
3 years ago
If you delete a file from removable media, it is stored in the recycle bin where you can recover it until you empty the recycle
Natasha2012 [34]

The appropriate response is no. why you can't discover it. After we erased our information, the information will be put away recycle bin, on the off chance that you purge the reuse receptacle, the information will be erased, and in the meantime, Windows will list the space as accessible room. On the off chance that you cover the recycle bin with other data's, the information put away before will really lost, so in the event that you need to recuperate the information in our recycle bin, don't attempt to cover it with something else.

<span>On the off chance that you may need to recuperation it, For standard individuals, we can't recuperation it straightforwardly, on the off chance that you have enough cash, you can send it to a few information recuperation organization to acknowledge proficient recuperation, however to the extent I am concerned, few of us can pay for it in view of a few information, you may feel frantic, yet another way, is attempt to utilize a few information recuperation programming.</span>

5 0
3 years ago
Convert<br> 0.625 to binary
Anastaziya [24]

\huge{ \rm{Question:}}

Convert

0.625 to binary

\huge{ \rm{Answer:}}

Translate 0.625 into a fraction. We all know that 0.5 is ½. We know that the remainder, 0.125, is ⅛. Add them together, and you get ½ + ⅛ = ⅝.

Now, in binary, the positions to the right of the point are , which is ½, ¼, and ⅛ respectively.

⅝ is 5 × ⅛. 5 in binary is 101. So, ⅝ is

= 0.101

8 0
2 years ago
What is the advantages and disadvantages of hardware devices and software devices ?
yulyashka [42]

Answer:

Advantages of hardware:

Physical existence

Multitasking

Speedy

Disadvantages:

Costly as different equipment cost differently

Time consuming

requires space

Privacy issues

Explanation:

Advantages of Software:

Less costly

Improved privacy controls

Requires no space

Disadvantages:

Does not have physical existence

hacking and cyber attacks may steal important information

Regular updates required

3 0
3 years ago
Other questions:
  • Why is it more secure to require a user to press ctrl+alt+delete to log on rather than displaying the windows welcome screen?
    15·1 answer
  • Fill in the blank. Do not abbreviate.
    6·1 answer
  • What would provide structured content that would indicate what the code is describing ?
    8·1 answer
  • In the table below identify the data type that would be most suitable for the second field
    14·1 answer
  • Consider two communication technologies that use the same bandwidth, but Technology B has twice the SNR of technology A. If tech
    14·1 answer
  • How does a search engine use algorithms to provide search results?
    15·2 answers
  • A list is a collection that ______________
    9·1 answer
  • Which statement correctly differentiates how to use list and table styles?
    12·2 answers
  • I'm in Paris and want to take a picture of my mom in front of the Eifel Tower. I want both her and the tower to be in sharp focu
    14·2 answers
  • Hola, alguien aquí me podría ayudar dándome ideas a cerca de office (Word, PowerPoint o Excel) estoy desesperada no puedo pensar
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!