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]
3 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]3 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
Which of the following is NOT a type of cable used in wired networks?a) Unshielded coaxialb) Coaxialc) Unshielded twisted-paird)
zysi [14]

Answer:

I think it is unshielded coaxial. Not 100% sure.

Explanation:

5 0
4 years ago
In 2007, __________ Floridians died in alcohol-related collisions. A. 501B. 1,051C. 5,015D. 10,839
wel

1000 people died of an alcohol addiction

4 0
4 years ago
Which social networking function came first?
amm1812

D, Online bulletin boards.


♣Amaranthine
3 0
3 years ago
Read 2 more answers
WILL GIVE 100 POINTS AND GIVE BRAINIEST TO THE FIRST PEOPLE THAT ANSWER CORRECTLY!!!!!! Marcus wants to create a spreadsheet wit
maks197457 [2]

Answer:

tell me bar

Explanation:

5 0
4 years ago
Read 2 more answers
What does it mean for a computing system to have an interface? A. An interface is a conduit through which the user can interact
Wittaler [7]

Answer:

An interface device (IDF) is a hardware component or system of components that allows a human being to interact with a computer, a telephone system, ...

Explanation:

5 0
1 year ago
Other questions:
  • Who made the Apple company?
    9·2 answers
  • Where should i go if i want to begin learning how to code a video game. What are your recommendations to a 16 yr old to learn co
    13·1 answer
  • Symbic Foods, a chain of fast food restaurants, has included a drop-down menu on its main Web site. With this drop-down menu, pe
    13·1 answer
  • The kings and queens of England are listed in a relation Kings(name,nickname,house,beginReign,endReign). Their name is unique, e
    8·1 answer
  • Given the module description:________.
    11·1 answer
  • What phobia is a fear of computers or working on a computer?
    6·1 answer
  • The amount of pressure a power source creates to move electrons. *
    9·1 answer
  • What are the main dimensions of information systems
    8·1 answer
  • What is the meaning of url <br>​
    7·1 answer
  • When scriptwriters are writing scripts, why do they have to write them in accordance with industry standards?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!