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

what is bit and byte in computer​

Answers

A bit is the smallest unit of information a byte is to see how many bits need to be represented (letters/characters)

Hope this helps

The First Amendment of the Constitution is one of the most important parts of the Bill of Rights. What specific rights does this amendment guarantee to every American citizen?

Answers

Answer:

The First Amendment to the U.S. Constitution protects the freedom of speech, religion and the press. It also protects the right to peaceful protest and to petition the government

Explanation:

if this answer is correct make me as brainlelist

Answer:

its guarantees the freedom of speech, religion, and the freedom of the press.

Explanation:

Do saving and loans associations have different categories?

Answers

Answer:

No

Explanation:

Because Savings and loan associations (S&Ls) are one of four types of "banks", there only one of four, not two of four

HELP ME!!! I WILL GIVE BRAINLY THINGY!!!

What does the code if (num2==50){ do?

Answers

Answer:

What subject is this?

Explanation:

is this math ?????????????????????

You have purchased a used computer from a computer liquidator. When you boot the computer, you find that there has been a password set on the BIOS. You need to clear the password so that you can edit the CMOS settings. What should you do

Answers

Answer:

What you should do is to move the motherboard jumper.

Explanation:

Based on the information given in a situation where you boot the computer system in which you find out that there was a password set on the BIOS which full meaning is BASIC INPUT/OUT SYSTEM which means that if You need to clear the set password in order for you to edit the CMOS settings which full meaning is COMPLEMENTARY METAL OXIDE SEMICONDUCTOR What you should do is for you to move the MOTHERBOARD JUMPERS reason been that jumpers will help to set or configure the MOTHERBOARD which is the most important part of a computer and the brain of a computer in order to clear the password so that CMOS setting can be edited.

What are the advantages and disadvantages of top-down and bottom-up programming? How would you decide which one to use? Do you approach problems in your real life from a bottom-up or top-down approach?

Answers

Answer:

Question: What are the advantages and disadvantages of top-down and bottom-up programming?

Answer:

Top-down programming is a process of writing programming codes that contain specific instructions for a computer to carry out the instructed task. Usually, Top-down programming comes as software that enables the division of problems that are initially complex into simpler parts. An example is a kind of software developed to give loans to worthy clients. The software may be broken down further to check the bank statements of the client, calculate the earning and spending capacity of the client, Amount paid on utilities.

Advantages of Top-down programming:

1. Top-down programming makes teamwork possible as a system is divided into sub-systems which individuals can handle separately before merging the sub-systems together.

2. Checks and testing become easy.

Disadvantages of Top-down programming:

1. Breaking systems into parts may be time-consuming as there is a need for more planning before working on individual sub-systems.

2. Error could be possible.

Bottom-up programming is a software of a method of design which is opposite to what the top-down programming does as the bottom-up programming works on the sub-systems first and then combine later into a bigger system. This makes use of the existing resources with the aim of generating a bigger result.

Advantages of Bottom-up programming:

1. Adaptability - Bottom-up programming makes adaptability easier.

2. When used in a company it gives all workers the room to make a contribution towards achieving bigger results, improving operations generally.

3. It makes one start a bigger project with the available resources.

Disadvantages of Bottom-up programming:

1. Result could be affected as some workers lack the needed experience to execute some tasks successfully.

2. Lack of desired unity among workers with differences in objectives resulting to endangering the result.

Question: How would you decide which one to use?

Answer:

It depends on the picture of how the result would look like, the goal of the organization employing it, the skill-set among workers available to do the task, the nature of the task. If a larger goal is to be achieved, smaller sub-systems could be used and joined at the end to get a system meaning bottom-up programming would be used. In cases for instance where output is to be determined for instance staff salaries, the output would be broken into simpler units to allow solutions for separate units then we could use top-down programming.

Question: Do you approach problems in your real life from a bottom-up or top-down approach?

Answer:

I approach problems from a top-down approach because it allows checks and testing easy, and the act of breaking systems into sub-systems makes it easy for me to approach each sub-system with a result-oriented plan.

Answer:

Some advantages of top-down are that you can start off from what you know and figure out what you need to complete it, the advantage to bottom-up is that you can make something new . if you are starting something from scratch and you don't know what the end goal might be you would use bottom-up but if you already have an idea or the final product of what you want you would go with the top-down approach.

Hope this helpedHave a great day!

Kali, a Python programmer, is using the turtle module to write the word “hello.” Which code should she use to indicate the location to begin writing the word?

Answers

Answer:

c

Explanation:

write a c++ program that prints the intial letter of any name​

Answers

Answer:

#include<iostream>

using namespace std;

int main(){

char str[20];

int i=0;

std::cout<<"Enter a name:" ;

cin>>str;

cout<<*str;

while(str[i]!='\0'){

if(str[i]==' '){

i++;

cin>>*(str+i);

}

i++;

}

return 0;

}

guess who is in the cheater cage lol

Answers

Oh oop- lol that’s interesting

Communication of the binary data via the voltage level for each time interval.
a
voice assistant
b
machine language
c
voltage
d
digital signal

Answers

Answer:

D

Explanation:

Answer:

D. Digital signal

Explanation:

Edge 2022

what are the atoms in grp one? periodic table. I am going to mark as brainliest ​

Answers

Answer:

Atoms in group 1:

H

Li

Na

K

Rb

Cs

Fr

"Jan23" can be stored using which data type? O an alphanumeric string O a boolean operator o characters floating point numbers​

Answers

Answer:

Alphanumeric string

Explanation:

Answer:

a. an alphanumeric string

Explanation:

got it right on edge

an early type of GUI is created, which includes windows, pop-ups, icons, and menus. What year did this happen? Please help!!! quick.

Answers

Answer:

1979

Sources:

Wired

InventHelp

hope i helped :D

In which situation is coauthoring of presentations primarily utilized?

A reviewer must be able to make changes to a presentation after an author creates it.
Multiple authors must be able to simultaneously make changes to a presentation.
Multiple reviewers have to be able to view one another’s changes after they are made.
One author and one reviewer work on a presentation at different times.

Answers

Answer:

A i belive

Explanation:

Answer:

B) Multiple authors must be able to simultaneously make changes to a presentation.

Explanation:

Co indicates being part of a whole. So this means that two or more authors are working on this project simultaneously. Such as co-management; two bosses working together in an equal position.

list and explain three computing devices from the 20th century​

Answers

Answer:

Calculating Machine

Graphic tablet.

Touchscreen

Explanation:

Hope this helps.

Brain-List?

Answer:

1. The First Calculating Machine (Pascaline)

2. Jacquard's Loom

3. The First Pocket Calculator

Explanation:

1. Pascaline was the first calculator or adding machine to be produced in any quantity and actually used. It was deigned at about 1642-1644.

2. Jacquard Loom is an attachment for powered fabric looms

3. The first truly pocket-sized electronic calculator was the Busicom LE-120A "HANDY" It was marketed in 1971.

What is the answer for 2.8.10 word games? This is what I have so far, but I can’t seem to be able to figure out the bananaSplit public strings.

Answers

Answer:

 public String bananaSplit(int insertIdx, String insertText) {

     return word.substring(0, insertIdx) + insertText + word.substring(insertIdx);

 }

Explanation:

Do you have the other parts of the WordGames class?

2. Media sharing websites let you post photos and videos to share with other people. What are the benefits and drawbacks of using these websites?

Answers

Media sharing websites let you post photos and videos to share with other people. The benefit is that we are up to date and get all the news as well as information worldwide.

What is company's website?

The website of the company is all web sites which is operated by any occupied company or via any occupied company conducts the business. Any business website is a website that is designed in such a way that it can represent the identity of a business on the internet.

Company's name and fame id totally depends upon advertisement and its products and websites play an important role in order to make company popular and due to this reason company used the website or designed the website in unique and knowledgeable manner.

Therefore, Media sharing websites let you post photos and videos to share with other people. The benefit is that we are up to date and get all the news as well as information worldwide.

Learn more about website here:

https://brainly.com/question/19459381

#SPJ2

How should students properly use media in a presentation? Check all that apply
⬜incorporate images that are irrelevant but interesting
⬜engage viewers by adding variety
⬜stimulate the senses of the viewer
⬜clarify relevant details in the text
⬜select songs that decrease the presentation’s impact

Answers

Answer:

engage viewers by adding variety

stimulate the senses of the viewer

clarify relevant details in the text

Answer:

B,C,D for short

Explanation:

6
development with reference to Nepal.
Mention the objectives of sustainable development,
How can you relate the role of environment while can​

Answers

Answer:

objective of sustainable development are:

Explanation:

1.to help in poverty alleviation

2.to conserve the environment effectively

3.to gain human development and progress

4.to use resources and means carefully

Jabari is writing pseudocode for a new video game he wants to create. What should he include in his pseudocode?

a
Everyday language that is easy to understand

b
Formatting with no indentations

c
The actual code used for the game

d
Words usually only programmers are familiar with

Answers

Answer:

The answer is "Option c".

Explanation:

The Pseudocode is a definition of actions in an algorithm or some other method of software engineering. It also uses regular programming language, formal conventions, and is associated with human learning rather than computer learning, and the wrong choice can be defined as follows:

In choice a, It is wrong because there are so many languages, and it is not easy to understand all.In choice b, It is wrong because it is used for better understanding.In choice d, it is wrong because words are also not only common to programmers.

Answer:

The actual code used for the game

In
the first computer ran a program from memory.
0 1942
1950
1948
1968

Answers

The first computer to run a program from memory was 1950.

Write 5-7 sentences about your own personal observations in which you have been part of a "filter". You might have experienced this is in your Twitter feed, specific advertisements, or your search engine results. Be specific.

Answers

Answer:

Answered below.

Explanation:

I made a search for a product on an online grocery store. The search results came in and I bought the product. On subsequent visits to the grocery store website or on browsing other sites, I had special advertisements pop up. These advertisements were suggesting products to me similar to the one I bought on the grocery store. It was a targeted advertisement that had been sent based on my recent searches and purchases on the site. So I knew that was a filter.

how do i get around a school related block

Answers

Answer:

try putting "uk-" or "us-" depending on where you are, you could also go through your settings and try to allow everything.

Answer:

Some schools have the option to block only on regular tabs, try going into settings and disabling the block to go on incognito tabs.

Another option would be to use a different web browser, something less known but good enough that it works and isnt blocked.

You can also find certain things on online where it tells you what websites to go to, then copy a link and paste it down into the search bar where the page will come up unblocked.

I hope this helped!

PS: If you go into certain websites, block third party cookies. ;)

Users of a _____ database have access through their personal computers linked to local or wide area networks

Answers

Answer:

Company

Explanation:

A company database is a database of a firm or organization that contains the information about the firm's employees, their products, services, and as well their client's and customers' details.

This is often kept on the main database server and arranged and organized by a database administrator.

Hence, Users of a COMPANY database have access through their personal computers linked to local or wide area networks

A CD and a DVD are both secondary storage devices, explain to a friend the difference between both​

Answers

Answer:

i dont have any friends to explain it to

Explanation:

help me i dont know this i suck at it

Answers

Answer:

Compiler, High level, Low level

Explanation:

I don't know about the last 2  

Website designers work on the code and programming of a website, not the style or layout of the site.

Answers

Answer:

False

Explanation:

Website designers design how the site looks not works

Click to review the online content. Then answer the question(s) below, using complete sentences. Scroll down to view additional
questions
Online Content Site 1
Why isn't a good idea to study in bed?

Answers

Answer:

yes.. it is not good.

Explanation:

because its can calm our mindy & sleep quickly.

Answer:

I think avoiding stress and something/ anything disturbing your health is an effective conflict. In my opinion avoiding stress and anything disturbing your health is bad because the more time you ignore it the worse it get's.

Explanation:

I got it right on Edg.

Proof:

What is the highest numeral in a decimal code?

A. 9
B. 5
C. 2
D. 1

Answers

Answer:

9

Explanation:

1.8, 1.9, 2.

~theLocoCoco

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.

Other Questions
Write (-2 2i) + (10 4i) as a complex number in standard form.A. -4 + 6iB. 8 6iC. 6D. 12 6i 1/5+1/3 answer and 3/4-1/8 1. Why might an ethical consumer buy goods she knows are manufactured by unionizedworkers?O It helps safeguard the environment.O It reduces waste in the marketplace.OIt helps workers receive better benefits.O It reduces the number of products for sale. Why do you think the sugar beets are harvested in the Fall? Which graph shows the following system of equations and its solutions? -0.1x-0.3y=1.2 and 0.2x-0.5y=2 Which statement is true about meiosis?It helps an organism grow in size.It replaces dead or damaged cells.It produces four genetically identical gametes.It is a source of variation in sexually reproducing organisms. The process of starting, organizing, managing, and assuming the responsibility for a business is called capitalism.a. Trueb. False Which sentence has correct punctuation?These are my favorite hobbies: puzzles, origami, and tennis.I really like: puzzles, origami, and tennis.Tabsolutely love: puzzles, origami, and tennis.My favorite hobbies are: puzzles, origami, and tennis. the daily wages of 80 workers of a factory:- DAILY WAGES ($): 500-600,600-700,700-800,800-900,900-100012,,,,,,,,,,,,17,,,,,,,,,,,,,,28,,,,,,,,,,,,,14,,,,,,,,,,,,,,9NO.OF WORKERS find the mean of daily wages of the workers of the factory by using an appropriate method [step diviation method] si una porcion es de 228 gramos cuantos gramos contiene el producto If the same total travel at the speed of 0.05 m/s for 40 seconds, how far would it have gone? Describe the 2 ways the Senate affects policies? This is the one that will decide my note, help once more please A survey of us adults found that 11% think that congress is a good reflection of american views. you rnadomly select 35 us adults and ask them whether they think tha tocngress is a good reflection of american views.Find the probability that the number who say yes is (a) exactly 8, (b) at least 10, and (c) less than 5, and (d) identify any unusual events. Explain. add me on the gram deirdre_wasjazzy Which art element refers to areas with only 2 dimensions such as squaresand circles? Explain ONE instance in which the Spanish resorted to the type of actions threatened in the third paragraph. If clouds were made of cotton-candy what is rain 9. A student notices that wearing darker colors in sunlight makes him feel warmer, so he decides to conduct an experiment. He takes five pieces of differentcolored cloth and wrapseach one around a water bottle. He then places all five bottles in direct sunlight and measures the temperature of the water in each bottle an hour laterWhat is the dependent variable in this experiment?O the time he leaves it in the sunlightO the amount of water in each bottleO the color of the clothO the temperature of the water Which statement describes the location of the tigris and Euphrates river A. The rivers are southeast of the Red Sea.B. The rivers are northwest of the Gaza Strip.C. The rivers are southeast of the Arabian Sea.D. The rivers are northwest of the Persian Gulf.