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
3 uses for auto formatting
zalisa [80]
Auto formatting is a computer software feature that automatically change the appearance of texts. Uses of auto formatting include the following:
it can be used to quickly apply or change automatic formatting.
It can be used to give a professional look to a document with minimal efforts.
the internet and network hyperlink option can be used to format email addresses and URL as clickable hyper link fields. 
The border line option can be used to apply paragraphs border styles to one's documents.
The table option can be used to create a table. 

3 0
3 years ago
List and describe the five moral dimensions that are involved in political, social, and ethical issues. Which do you think will
lukranit [14]

The five moral dimensions are:

  • Information rights and obligations.
  • Property rights and obligations
  • System quality.
  • Quality of life,
  • Accountability and control.

I see that Quality of life is most difficult for society to deal with as there ae lots of rich and poor people and the government have not been able to bridge the gap between them.

<h3>What are the morals about?</h3>

The five main moral dimensions that are known to be written above are said to be tied together in regards to ethical, social, and political issues that are seen in any information society.

Therefore, The five moral dimensions are:

  • Information rights and obligations.
  • Property rights and obligations
  • System quality.
  • Quality of life,
  • Accountability and control.

Learn more about moral dimensions from

brainly.com/question/15130761

#SPJ1

3 0
2 years ago
How many months have 28 days?
Reika [66]

Answer:

All months of the year have at least 28 days, while February is the only month that is comprised of only 28 days (except for leap years)

5 0
3 years ago
Use the AND function with appropriate arguments in cell H11 to determine if there is a force out at third base. There is a force
Pie

Answer:

=AND($C11 = "Yes", $D11 = "Yes")

Explanation:

The AND function takes conditional inputs and tests if each of them are TRUE. If all of the inputs are TRUE, the function will output TRUE but if any one of them are not the function will output FALSE. This scales to multiple inputs but this example only has two conditions. It is important to remember that we want to compare a string so our condition must be "Yes", not just Yes.

We also use a relative cell reference, "$", on the columns C and D since we always want to use the "Runner on 1st" and "Runner on 2nd" columns.

6 0
4 years ago
Select the correct answer. Arcade games such as Donkey Kong, Mr. Do! , and Venture were adapted from arcade titles to home conso
Andrew [12]

Answer:

D. Magnavox

hgjvyihbnjbuhklnk. hvgvjnm;lkbhkvkbl.

4 0
4 years ago
Other questions:
  • Gus has decided to organize his inbox on June 26th by using folders and deleting irrelevant messages
    10·2 answers
  • Fill in the blank
    15·1 answer
  • Al and Bill are arguing about the performance of their sorting algorithms. Al claims that his O(N log N)-time algorithm is alway
    13·1 answer
  • Why do bats sleep upside down
    7·1 answer
  • No down payment, 18 percent / year, payment of $50/month, payment goes first to interest, balance to principal. Write a program
    9·1 answer
  • What can a user modify on a business card using the Edit Business card in the dialog box?​
    8·1 answer
  • Write an algorithm and flowchart to display H.C.F and L.C.M of given to numbers.​
    9·1 answer
  • What is an insertion point?
    6·1 answer
  • What is Smart Content Profits all about?
    10·2 answers
  • Can any software run on any processor
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!