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
Genrish500 [490]
2 years ago
13

Write a do-while loop that asks the user to enter two numbers. The numbers should be added and the sum displayed. The user shoul

d be asked if he or she wishes to per- form the operation again. If so, the loop should repeat; otherwise it should terminate.
Computers and Technology
1 answer:
iVinArrow [24]2 years ago
5 0

The do-while loop for the given problem is shown below.  

do  

{  

  // user asked to enter two numbers  

  cout<<"Enter two numbers to be added."<<endl;  

  cin>>num1;  

  cin>>num2;  

  sum = num1 + num2;  

 

  // sum of the numbers is displayed  

  cout<<"Sum of the two numbers is "<<sum<<endl;  

  // user asked whether to perform the operation again  

  cout<<"Do you wish to continue (y/n) ?"<<endl;  

   cin>>choice;  

}while(choice != 'n');  

The variables to hold the two numbers and their sum are declared as float so that the program should work well for both integers and floating numbers.

float num1, num2, sum;

The char variable is taken since it holds only a single-character input from the user, 'y' or 'n'.

char choice;

The whole program is given below.

#include <iostream>

using namespace std;

int main() {

float num1, num2, sum;

char choice;  

do  

{  

  // user asked to enter two numbers  

  cout<<"Enter two numbers to be added."<<endl;  

  cin>>num1;  

  cin>>num2;  

  sum = num1 + num2;  

  // sum of the numbers is displayed  

  cout<<"Sum of the two numbers is "<<sum<<endl;  

  // user asked whether to perform the operation again  

  cout<<"Do you wish to continue (y/n) ?"<<endl;  

  cin>>choice;  

}while(choice != 'n');

cout<<"Quitting..."<<endl;

}

You might be interested in
Energy vampire devices can draw power even when they are turned off or in standby mode?
just olya [345]
Yes that is correct.
3 0
2 years ago
Consider the partially-filled array named a. What does the following loop do? (cin is a Scanner object)int[] a = {1, 3, 7, 0, 0,
boyakko [2]

Answer:

Option 1: May crash at runtime because it can input more elements than the array can hold

Explanation:

Given the code as follows:

  1.        int[] a = {1, 3, 7, 0, 0, 0};
  2.        int size = 3, capacity = 6;
  3.        int value = cin.nextInt();
  4.        while (value > 0)
  5.        {
  6.            a[size] = value;
  7.            size++;
  8.            value = cin.nextInt();
  9.        }

From the code above, we know the <em>a</em> is an array with six elements (Line 1). Since the array has been initialized with six elements, the capacity of the array cannot be altered in later stage.

However, a while loop is created to keep prompting for user input an integer and overwrite the value in the array started from index 3 (Line 4- 9). In every round of loop, the index is incremented by 1 (Line 7). If the user input for variable <em>value</em> is always above zero, the while loop will persist.  This may reach a point where the index value is out of bound and crash the program. Please note the maximum index value for the array is supposedly be 5.  

8 0
2 years ago
3. For “Incident Energy Analysis” What body parts are involved in the distance
krek1111 [17]

The body part that is close to the arc flash boundary is the energized conductors or circuit parts.

<h3>What is the distance of an arc flash?</h3>

The working distance is known to be the distance that exist between a person and the center of an arc flash.

Note that The body part that is close to the arc flash boundary is the energized conductors or circuit parts.

Learn more about Energy from

brainly.com/question/13881533

#SPJ1

7 0
1 year ago
What does ascii stand for?
tamaranim1 [39]
ASCII—American Standard Code for Information Interchange
7 0
3 years ago
Read 2 more answers
Why is homophobia a big thing?
BigorU [14]

I don’t know. It’s an independence thing from society I guess
7 0
2 years ago
Read 2 more answers
Other questions:
  • In what way(s) did the password you tried to use not meet the password policy requirements?
    14·1 answer
  • Terrence smiles at his customers, helps his coworkers, and stays late when needed. What personal skill does Terrence demonstrate
    10·2 answers
  • Define the acronym WAECUP and its components
    15·1 answer
  • The overall purpose of a food guide is________.
    11·1 answer
  • This is not school related in anyway but. I used to play this videogame on my computer years ago, but i cannot remember the name
    13·2 answers
  • The approved detail design resulting from the __________ serves as a basis for making the decision to begin production.
    8·1 answer
  • What is renewable energy
    13·2 answers
  • What is lasso tool write the name of any modelling and animation software<br>​
    8·1 answer
  • Iciples UI
    12·1 answer
  • Sub to the channel plz plz
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!