Write a program to have the computer guess at a number between 1 and 20. This program has you, the user choose a number between 1 and 20. Then I, the computer will try to my best to guess the number. Is it a 18? (y/n) n Higher or Lower (h/l) l Is it a 5?(y/n) n Higher or Lower (h/l) h Is it a 10? (y/n) y I got tour number of 10 in 3 guesses.

Answers

Answer 1

Answer:

This question is answered using C++ programming language.

#include<iostream>

#include <cstdlib>

#include <ctime>

using namespace std;

int main(){

   int num, computerguess;

   char response, hl;

   cout<<"Choose your number: ";

   cin>>num;

   srand((unsigned) time(0));

   int high = 20;    int low = 1;    int guess = 0;

   computerguess = low + rand() % high;

   cout<<"Is it "<<computerguess<<" ?y/n: ";

   cin>>response;

   while(response == 'n'){

       cout<<"Higher or Lower? h/l: ";

       cin>>hl;

       if(hl == 'h'){            low = computerguess+1; }

       else{   high = computerguess-1; }

       guess++;

       computerguess = low + rand() % high;

       cout<<"Is it "<<computerguess<<" ?y/n: ";

   cin>>response;

   }

   cout<<"I got your number of "<<num<<" in "<<guess+1<<" guesses.";

   return 0;

}

Explanation:

This declares num (user input) and computerguess as integer

   int num, computerguess;

This declares response (which could be yes (y) or no (n) and hl (which represents high or low) as char

   char response, hl;

This prompts user for input

   cout<<"Choose your number: ";

This gets user input

   cin>>num;

This allows the computer be able to generate different random numbers at different intervals

   srand((unsigned) time(0));

This declares and initializes the range (high and low) to 20 and 1 respectively. Also, the initial number of guess is declared and initialized to 0

   int high = 20;    int low = 1;    int guess = 0;

Here, the computer take a guess

   computerguess = low + rand() % high;

This asks if the computer guess is right

   cout<<"Is it "<<computerguess<<" ?y/n: ";

This gets user response (y or n)

   cin>>response;

The following iteration is repeated until the computer guess is right

   while(response == 'n'){

This asks if computer guess is high or low

       cout<<"Higher or Lower? h/l: ";

This gets user response (h or l)

       cin>>hl;

If the response is higher, this line gets the lower interval of the range

       if(hl == 'h'){            low = computerguess+1; }

If the response is lower, this line gets the upper interval of the range

       else{   high = computerguess-1; }

This increments the number of guess by 1

       guess++;

Here, the computer take a guess

   computerguess = low + rand() % high;

This asks if the computer guess is right

   cout<<"Is it "<<computerguess<<" ?y/n: ";

This gets user response (y or n)

   cin>>response;    }

This prints the statistics of the guess

   cout<<"I got your number of "<<num<<" in "<<guess+1<<" guesses.";


Related Questions

PLEASE HURRY!!
Look at the image below!

Answers

The answer would be 2&5 because this is correct
The answer should be 2&5 I’m not 100% sure on this but it makes the most sense

which of the following types of correspondence is used to inform the reader of new information such as a policy change

Answers

Answer: Memo

Explanation: Have a good day, pls mark me brainliest <3

which part of the brain controls the movement of muscles​

Answers

Answer:

PLEASE MARK AS BRAINLIEST

Explanation:

Cerebellum

Cerebellum. The cerebellum (back of brain) is located at the back of the head. Its function is to coordinate voluntary muscle movements and to maintain posture, balance, and equilibrium.

The data type of 17.3 should be ________________.

int
float
str
list
Please answer quick.​

Answers

Answer:

float

Explanation:

Answer:

17.3 should be a float

Explanation:

Float type is a data that is contain a decimal number

Can someone help me I am coding.

Answers

Answer:

i will help u

Explanation:

what did you want

How does entertainment relate to coding?

Answers

Answer:

not sure if this is the type of answer you're looking for but: Entertainment can relate to coding because in TV shows and movies, there is lots of editing. Especially with cartoons. Inorder to make these, we have to use coding. This can even relate to real life plays and preformenses depending on how much technology you use to preform them.

If you would like to compare information on two different Web pages, you should _____.
scroll through the pages
the home page
use tabs
organize bookmarks

Answers

Answer:

Use Tabs

Explanation:

I had this lesson on odyessy ware and this was right the other guy is wrong

Answer:

Use Tabs is also correct on Edge nuity

Explanation:

i have Keyboarding and Apps


An identifier that allows multiple elements in an HTML document to be
styled in the same way

Answers

Answer:

CSS , (Possibly Divs)

Explanation:

I have picked CSS, and possibly Div's as my main explanation and answer here is why.

CSS - Cascading Style Sheets, this allows you to edit multiple elements in a HTML document, such as the color or any CSS attribute.

If you would like to learn more about CSS, and the multiple options that CSS provides such as Internal Styles, External Styles, lastly In-line styles. I highly recommend the resource "W3Schools".

DIV's - Divs are basically like a container, where you can input styles into this container that can effect those elements such as if I want the background-color, of the div it would effect all the elements inside that div. However, I said this could be a possibility since it isn't CSS where it is styled however you can group these elements to one div. You can also edit the CSS of the Div to effect it.

Two light bulbs are connected in a series circuit. You add a third bulb in a series. All three bulbs are identical. Which of the following will happen?

Answers

Answer:

The bulbs would becom dim

Explanation:

The 3rd bulb adds too much resistance that the other bulbs go dim

What is a resistor?
O A switch
O A light bulb
O A battery

Answers

Answer:

A Battery would be the correct awncer

For Internet Protocol (IP) v6 traffic to travel on an IP v4 network, which two technologies are used

Answers

Answer:

These technologies are: Dual Stack Routers, Tunneling, and NAT Protocol Translation.

Explanation:

Dual Stack Routers -  This is the process in which a router’s interface is attached with IPv4 and IPv6 addresses

Tunneling -Tunneling is used as a medium to help the different IP versions  communicate with the transit network.

NAT Protocol Translation -  This helps the IPv4 and IPv6 networks communicate with each other since they do not understand the IP addresses of each other since, they are different IP versions.

The two technologies that are used when Internet Protocol (IP) v6 traffic travel on an IP v4 network are datagrams and ipv6.

A datagram can be defined as a transfer unit that is associated with a packet-switched network.

Internet Protocol version 6 (IPv6) is a protocol used for packet-switched inter-networking.

The IPv6 is a protocol used for end-to-end datagram transmission through multiple Internet Protocol networks.

In conclusion, the two technologies that are used when Internet Protocol (IP) v6 traffic travel on an IP v4 network are datagrams and ipv6.

Learn more in:

https://brainly.com/question/14851068

If you had three extra siblings, what would be your birth order and what personalities would you like them to have?

Answers

Answer:

mixed personalities l

that will be cool

Answer:

I already have 4 step brothers, 2 real brothers, 1 step sister, and a half sister, so 3 more people would be a lot. If I got to pick their personalities and gender, I would want 1 more sister and 2 more brothers. I would watn a more alt brother, a more fem brother, and an indie sister. Kinda just an aesthetic type for them.

PLEASE ASAP!!

Today, most film editors manually cut and splice the actual film footage once it arrives.


O True
O False

Answers

The correct answer should be true, as their job is to *edit* the footage.

Answer:

True

Explanation:

edg2021

The film editor is such an important person on a film that he is often hired before the cast and other crew. This editor is responsible for revising the filmed footage until it becomes the finished film. The editor begins by reading the script to get familiar with the story. It is important for the editor to know the script because film scenes are generally shot and edited out of sequence. When footage begins to come in, the editor reviews the footage and production notes provided by the director and production team. These notes contain details about the footage and the director’s comments about the footage. The editor then uploads or transfers the footage to computers in the editing bay and begins editing the footage into finished scenes. The editing bay is the control room with editing equipment, computers, monitors, and sound system where film editors manipulate plot, sound, graphics, and score to produce a well-constructed scene. This is a painstakingly detailed and time-consuming task

The Internet:

O A. only gives us access to our local communities.

O B. hinders our ability to influence people.

O C. limits us to local social networking sites.

O D. enables us to join global online communities.​

Answers

Answer:

D- it enables us to join global online communities.

Explanation:

Thanks to social media and other websites, content you produce can be seen all over the world.

select the correct option
and thanks

Answers

M cucumber
Should be the ans

Answer:

Cucumber

Explanation:

Cucumber has the largest portion. .08 kg/tray/day. The entire graph equals 100%, and the cucumbers take up 17.8% of it.

Help with my Nintendo DS please I now it’s not school related but I need it for my little sister

Answers

Answer:Go to settings and do factory reset!

Explanation:

Four students measured the mass of a piece of metal whose accurate mass is 34.75g. Their results are 34.2g, 33.75g, 35.0g, and 34.69g. Explain whether the results are precise or accurate​

Answers

Answer:

The given data are more precise than they are accurate

Explanation:

From the given measurements, we have;

The accurate mass = 34.75 g

The deviations from the accurate measurement is as follows;

34.2 g - 34.75 g = -0.55 g

33.75 g - 34.75 g = -1 g

35.0 g - 34.75 g = 0.25 g

34.69 g - 34.75 g = -0.06 g

For precision measurement, we find the average deviations as follows;

The sum of the deviations = -0.55 g - 1 g + 0.25 g - 0.06 g = -1.36 g

The average deviation = -1.36 g/4 = -0.34 g

For accuracy measurement, we find the average of the absolute deviations as follows;

The sum of the absolute deviations = 0.55 g + 1 g + 0.25 g + 0.06 g = 1.86 grams

The average absolute deviation = 1.86 g/4 = 0.465 g

Therefore, the magnitude of the average deviation is less than the magnitude of the absolute deviations, therefore, the given data are more precise than they are accurate

Major innovations made from the establishment of abucus to the 5th computer generation

Answers

Answer:

Cogs and Calculators

It is a measure of the brilliance of the abacus, invented in the Middle East circa 500 BC, that it remained the fastest form of calculator until the middle of the 17th century. Then, in 1642, aged only 18, French scientist and philosopher Blaise Pascal (1623–1666) invented the first practical mechanical calculator, the Pascaline, to help his tax-collector father do his sums. The machine had a series of interlocking cogs (gear wheels with teeth around their outer edges) that could add and subtract decimal numbers. Several decades later, in 1671, German mathematician and philosopher Gottfried Wilhelm Leibniz (1646–1716) came up with a similar but more advanced machine. Instead of using cogs, it had a "stepped drum" (a cylinder with teeth of increasing length around its edge), an innovation that survived in mechanical calculators for 300 hundred years. The Leibniz machine could do much more than Pascal's: as well as adding and subtracting, it could multiply, divide, and work out square roots. Another pioneering feature was the first memory store or "register."

Apart from developing one of the world's earliest mechanical calculators, Leibniz is remembered for another important contribution to computing: he was the man who invented binary code, a way of representing any decimal number using only the two digits zero and one. Although Leibniz made no use of binary in his own calculator, it set others thinking. In 1854, a little over a century after Leibniz had died, Englishman George Boole (1815–1864) used the idea to invent a new branch of mathematics called Boolean algebra. [1] In modern computers, binary code and Boolean algebra allow computers to make simple decisions by comparing long strings of zeros and ones. But, in the 19th century, these ideas were still far ahead of their time. It would take another 50–100 years for mathematicians and computer scientists to figure out how to use them (find out more in our articles about calculators and logic gates).

Explanation:

Debugging is finding and fixing problems in an algorithm or program. True
or False.
False
True

Answers

The correct answer is True

Debugging is finding and fixing problems in an algorithm or program is True statement.

Debugging is indeed the process of finding and fixing problems, errors, or bugs in an algorithm or computer program.

When a program does not produce the expected output or behaves unexpectedly, programmers use debugging techniques to identify and resolve the issues.

This involves analyzing the code, checking for syntax errors, logical errors, and unexpected behavior, and making the necessary corrections to ensure the program functions correctly.

Thus, the given statement is True.

Learn more about Debugging here:

https://brainly.com/question/9433559

#SPJ6

The type of medium used to hide data in steganography is referred to as __________. This may be a photo, video, sound file, or Voice over IP, for example.

Answers

Answer:

:L

Explanation:

Answer:

symmetric cryptography

Explanation:

anybody wanna be friends?

Answers

i wouldn't mind......

yes Avacado?????????????????????

Match the image to its type.


Rgb messes up taking pics from a iPhone 11 to a computer sorry it looks bad

Answers

Warm Colors:

Red flowersOranges

Cool Colors:

Blue skiesPurple butterflies

Neutral Colors:

Brown woodWhite birds

Reds, oranges, and yellows are considered warm, and greens, teals, blues, and purples are considered cool. Colors such as white, black, brown, or gray are all neutral.

A common error by beginning programmers is to forget that array subscripts start with ________.
a. 0
b. the number of elements in the array
c. spaces
d. 1

Answers

Answer:.

Explanation:

What improved image quality in televisions?
A: FM technology
B: AM technology
C: color CRTs
D: black-and-white CRTs
E: coaxial cables

Answers

Answer:

coaxial cables are the answer

Name the stringed instrument that's known for its haunting sound, wide pitch capability, and large numbers in the orchestra.

A. Harp
B. Violin
C. Viola
D. Clarinet

The subject is Music Technology.

Answers

Answer:

VIOLIN

Explanation:

The VIOLIN is the stringed instrument that's known for its haunting sound, wide pitch capability, and large numbers in the orchestra.

I think the correct answer would be harp!! BRANLIEST plz

If you got band from a local library, what would be the reason for it besides shouting and talking? You're answer has to fit you're personality?

Answers

Answer:

I would get a band from the library because I check out ten books and returned them in a week. I also would just be in the library all the time and they would get frustrated. That or I would spend hours talking to a librarian about my favorite books and they would get fed up with me.

Which of the following is NOT true regarding fonts which should be used in memos?
O Typically serif fonts are used such as Times New Roman
O Typically sans-serif fonts are used such as Arial
O Headers should be 12-point font size
O Body text should be 10-point font size

Answers

Answer: Typically serif fonts are used such as Times New Roman.

Explanation: Have a gr8t day and pls mark me brainliest.

it was field day for the upper grades at Rock Creek School,
Each grade had to choose a team name and a color for their tee-shirts,
Use the clues below to figure out what each grade chose for their team name and tee-shirt color, each grade can chose one color and one team name.

- The third and fifth grades didn't choose an animal for their team name.

-The forth grade ended up with red tee-shirts with sharks on the.

-The fifth graders and tornadoes are not wearing teal.

-The bears are wearing green.

​​

Answers

Answer:

its c

Explanation:

can some one please help

Answers

Answer:

the thing is black for me. retake?

Explanation:

Soft skills are more likely to be transferable than hard skills?

True or false

Answers

Answer:

The correct answer is true.

Explanation:

Examples of Soft skills are

Communication TeamworkPositive Attitude etc.                              

These skill can be applied to any job. That is why we have said that soft skill are transferrable.

Now let look at hard skill,

Hard skill like programming in python. Making the architecture of computer. These skill can not be transferred to a new job like authoring a book.

so, hard skills are not easily transferrable.

Other Questions
If you were the leader of Germany ,what would u do about the refugees? Use evidence. Evidence that REFUGEES SHOULD BE ALLOWED TO ENTER THE COUNTRYevidence That REFUGEES SHOULD NOT BE ALLOWED TO enter the country The meeting of the First Continental Congress took place in Philadelphia which became the first capital of the United States. What is the capital of the United States now? How cold is it in texas rn? The development of market power by a firm is considered to be a market failure because firms with market power will 18 vocabulary words learned in 2 hours; 27 vocabulary words learned in 3 hours compare how is the overall chemical reaction for cellular respiration related to the overall chemical reaction for photosynthesis Helium (He), neon (Ne) and argon (Ar) are all colorless, odorless gases with low chemical reactivity. Based on the periodic table, which other element would also have those same properties? A comet's journey around the Sun may take hundreds of years. As the comet at last approaches the Sun, bits of ice and other material arethrown back from the Sun, creating the comet's "tail." After the comet has passed the Sun, its tail gradually disappears until there is little more leftof the visible comet than a ball of ice and gas hurtling through space.What happens last? 100 POINTS. Any Spanish speakers wanna help me out? Order the set of numbers from least to greatest. {63, -34, 36, -27, -13, and 12} Solve for b .-9 b = 27b = There are no values of x and y that make y = -x + 10 and y = 2x + 4 true at the same time. True or False Need help solving #7 please what is the dilution factor if you add a 0.1ml aliquot of a specimen to 9.9 dilutent How are the lives of enslaved people differ from the lives of free people of color? WHAT IS THE ANSWER FOR THIS PLZ!!! I WILL MARK BRAINLIEST!!! Which detail shows that Jing cares for others?A. She helps Shan with the silkworm cocoons.B. She plans to make hats for Shan's children's dolls.C. She does not have anything to give to the emperor's baby.D. She pays attention to her dream about the old woman. does the table below represent a function Which ordered pair is a solution of the inequality y < 3x + 1? A. (3, 2) B. (3, 14) C. (1, 3) D. (1, 6) In an activity, students are pulling marbles from a large jar containing blue and red marbles. In their sample, students will calculate the proportion of blue marbles. Which of the following sample sizes will have the largest sampling variability?5101520