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
juin [17]
4 years ago
5

Write a program that generates a random number between 5 and 15 and asks the user to guess what the number is. If the user’s gue

ss is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses the user makes until the user correctly guesses the random number. Then the program should display the number of guesses along with the following message Congratulations. You figured out my number. Suggest that you also give the user the opportunity to play the game again or quit.
Computers and Technology
1 answer:
stepan [7]4 years ago
4 0

Answer: The c++ program for the number guessing game is given below.

#include <iostream>

using namespace std;

// method declaration without parameters

void game();

int main() {    

char reply;

// calling the game method

game();  

cout<<"Would you like to continue with the game ? Enter y to continue. Enter q to quit the game. " <<endl;

cin>>reply;  

if(reply == 'y')

    game();      

if(reply == 'q')

    cout<<"Quitting the game..."<<endl;  

return 0;

}

void game()

{

   int num, guess, attempt=0;  

num = (rand() % 10) + 6;  

cout<<endl<<"Welcome to the game of guessing the correct number "<<endl;  

   do

{    

    cout<<"Enter any number between 5 and 15. "<< endl;

    cin>>guess;      

    if(guess<5 || guess>15)

    {

        do

        {

            cout<<"Invalid number. Enter any number between 5 and 15. "<<endl;

            cin>>guess;

        }while(guess<5 || guess>15);

    }  

    if(guess < num)

    {

        cout<<"Too Low"<<endl;

        attempt++;        

    }

    if(guess > num)

    {

        cout<<"Too High"<<endl;

        attempt++;          

    }      

}while(guess != num);  

cout<<"Congratulations. You figured out my number in "<<attempt<< " attempts."<<endl;

}

Explanation:

The expression

(rand() % 10)

generates a random number between 0 and 9. 6 is added to generate a random number between 5 and 15.

The integer variable attempt is initialized to 0.

Next, user is asked to guess the number. If the user enters an invalid input, the do-while loop begins until a valid input is received from the user.

    cout<<"Enter any number between 5 and 15. "<< endl;

    cin>>guess;      

    if(guess<5 || guess>15)

    {

        do

        {

            cout<<"Invalid number. Enter any number between 5 and 15. "<<endl;

            cin>>guess;

        }while(guess<5 || guess>15);

    }  

User is prompted to input the guess using the same do-while loop as above. Until the user guesses the correct number, the loop continues. Each incorrect guess by the user, increments the variable attempt by 1. This represents the number of attempts done by the user to guess the correct number.

    if(guess < num)

    {

        cout<<"Too Low"<<endl;

        attempt++;        

    }

    if(guess > num)

    {

        cout<<"Too High"<<endl;

        attempt++;          

    }  

The random number generation and the guessing logic is put in a separate method game().

The entry and exit from the game only is put inside the main method.

You might be interested in
. What is suboptimization?
Vera_Pavlovna [14]

Answer: Suboptimization is referred to as a term that has been approved for common policy mistake. It usually refers to the practice of concentrating on a single component of a whole and thus making changes which are intended towards improving that component and also ignoring its effects on other components.

3 0
3 years ago
Green Field county stadium is planning to conduct a cricket match between two teams A and B. A large crowd is expected in the st
PtichkaEL [24]

Answer:

RS422-A or RS-485

Explanation:

Mode Name: RS422-A

Well, this is the electrical interface. The microprocessor covers the logics to electrical signals, and these electrical signals are then transmitted over a long distance, which is less than 4000 feet through RS422-A. And this is a half-duplex mode with the multidrop receiver and one transmitter at a time, in master-slave format. A receiver is a slave and the transmitter is a master. And there can only be one transmitter at a time. Here, a PC collects the videos from all cameras, through a unified system, and this PC is connected to numerous receivers which are the Screens. Parallel transmission cannot be done over a single line, and it's noisy as well, and hence we stick to serial mode. and here half-duplex as one at a time need to deliver, and not both. Hence, RS422-A is the first mode. which is a half-duplex serial transmission mode.

Reason 1:

It's noiseless

Reason 2:

The number of receivers can be as high as 10.

As the second alternative option:

Mode Name: RS-485

This is even better and allows receivers as high in number as 32, and hence is better than RS-422A. The maximum distance allowed is around 4000 feet, and the rest is the same as RS-422A. it also supports half-duplex.

Reason 1: It's less noisy and even better than RS422-A

Reason 2: number of receivers, and as high as 32 are allowed.

Remember, however, Ethernet is a low distance network, though it also supports collision detection, and multiple access/ carrier detection or CSMA/CD. However, for this question requirement RS-422A and RS-485 network interface will work fine. In the case of ethernet, we have an Ethernet Interface card, which works as an Ethernet network interface. However, Ethernet is a short distance, and will not work here.

6 0
3 years ago
sales reps at universal containers use salesforce on their mobile devices. They want a way to add new contacts quickly and then
Mamont248 [21]

Answer:

Build a global action to create Contacts

Explanation:

Based on the information given the mobile solution that an app builder should recommend should be GLOBAL ACTION because global action enables new contact to be created quickly ,Global actions also enables the creation or update of records as well sending email, all without leaving the page the person is working on which is why GLOBAL ACTION is often recommended because it saves time.

6 0
4 years ago
Compute the present value of a $5,500 deposit in year 1, and another $5,000 deposit at the end of year 4 using an 8 percent inte
marusya05 [52]

Answer:

Explanation:

Present value is the value in the present of a sum of money, in contrast to some future value it will have when it has been invested at compound interest.

It can be calculated using future value formula below

A = P(1+r/100)^n

where

A = Future value

P = Present value

r = Rate of interest

n = time period

Present Value = Value at Year 1 + Value at Year 4

Calculating Value at Year 1

A = $5,500

r = 8%

n = 1

From A = P(1+r/100)^n ; Make P the subject of formula

P = A ÷ (1 + r/100)^n

Substitute in values

P = $5,500 ÷ (1 + 8/100)^1

P = $5,500 ÷ (1 + 0.08)

P = $5,500/1.08

P = $5092.5925926

P = $5092.59 ----

Present Value at Year 1 = $5092.59

Calculating Value at Year 4

A = $5,000

r = 8%

n = 1

From A = P(1+r/100)^n ; Make P the subject of formula

P = A ÷ (1 + r/100)^n

Substitute in values

P = $5,000 ÷ (1 + 8/100)⁴

P = $5,000 ÷ (1 + 0.08)⁴

P = $5,000/1.08⁴

P = $3675.149263982267

P = $3675.15 ----

Present Value at Year 4 = $3675.15

Present Value = Value at Year 1 + Value at Year 4

Substitute each value

Present Value = $5092.59 + $3675.15

Present Value = $8,767.74

8 0
4 years ago
How is the Microsoft Word 2013 window organized?
Alenkasestr [34]
The answer is (A): with contextual tabs for major groupings of editing features and ribbons with specific groupings to organize commands.


Contextual tab or tabs are hidden menu that appears when objects like images or texts are selected in programs like MS Word 2013. They typically contain one or more commands applicable to a selected text or object only. They are there in the Ribbon when you need them and disappear when you do not need them anymore. They are basically used for major groupings of editing features.
A ribbon on the other hand help users understand how commands are used directly and efficiently. It organizes a program’s features into a series of tabs.




6 0
4 years ago
Read 2 more answers
Other questions:
  • Wendy had been searching the internet for a great deal on jewelry. While looking at one site, a pop-up was displayed that told h
    12·1 answer
  • Each frame is composed of a number of colors recorded in digital format; we call these pixels. What information does the number
    15·1 answer
  • What commands will reset a network interface in Linux?
    13·1 answer
  • A customer states that when she removes the printed pages from her laser printer output tray, the black ink smears all over her
    14·1 answer
  • What is the most useful advantage of using the Slide Sorter view to rearrange slides instead of using the slide thumbnails in No
    13·1 answer
  • A user purchased a new smart home device with embedded software and connected the device to a home network. The user then regist
    5·1 answer
  • What does the revolver do?
    10·1 answer
  • Which of the following is not an example of a cyber crime?
    8·1 answer
  • What is the purpose of a web server? What is the purpose of a web browser?
    11·1 answer
  • Which description best applies to a macro?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!