answer.
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
xz_007
4 months 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:
zubka84 [1K]4 months ago
5 0

The do-while loop for this task is presented below.

do

{

// request the user to input two numbers

cout<<"Please input two numbers to add."<<endl;

cin>>num1;

cin>>num2;

sum = num1 + num2;

// display the sum

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

// ask the user if they want to continue

cout<<"Would you like to keep going (y/n)?"<<endl;

cin>>choice;

}while(choice!= 'n');

The variables for the two numbers and their sum are defined as float for compatibility with both integers and decimals.

float num1, num2, sum;

The choice variable is char since it only needs to hold a single character input from the user, either 'y' or 'n'.

char choice;

The complete program is structured as follows:

#include <iostream>

using namespace std;

int main() {

float num1, num2, sum;

char choice;

do

{

// request the user to input two numbers

cout<<"Please input two numbers to add."<<endl;

cin>>num1;

cin>>num2;

sum = num1 + num2;

// display the result

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

// query the user on continuing

cout<<"Would you like to keep going (y/n)?"<<endl;

cin>>choice;

}while(choice!= 'n');

cout<<"Exiting..."<<endl;

}

You might be interested in
On the planet Sigma, robots excavate chunks of a very precious cristaline. These chunks can be divided into smaller part only on
Amiraneli [1052]

Answer:

Begin the algorithm by assessing the ship's weight. Load the crystalline material onto the ship. Verify if the weight equals the ship's weight plus k pounds of crystalline; if it is not enough, load additional crystalline. If there is an excess, discard the surplus crystalline. Upon meeting the required weight, the ship can depart for planet Sigma.

Explanation:

The algorithm consistently monitors the ship's weight while loading with the total of the ship's weight along with k pounds of crystalline. This method ensures that the ship carries the maximum feasible amount of crystalline to planet Sigma.

7 0
3 months ago
Dan is a Civil Engineer for a company that builds nuclear power plants throughout the world. Which best describes the places he
oksian1 [950]
In a lab... C 
4 0
2 months ago
Read 2 more answers
Ishaan is confused between the terms webpage and website help him in understanding the difference between both​
maria [1035]

Answer:

A webpage serves as a single page within a website, while a website encompasses a collection of such pages offering valuable information.

Explanation:

Please follow

7 0
3 months ago
A network administrator has received the IPv6 prefix 2001:DB8::/48 for subnetting. Assuming the administrator does not subnet in
8_murik_8 [964]

Answer:

subnets=65536

Explanation:

As per our knowledge,

--> the address's interface ID portion begins at 64

--> there exists a 48 bit network prefix

therefore,

the bits available for subnets are = 64-48=  16

thus, by utilizing 16 bits, the number of subnets can be calculated as = 2^16 = 65535

6 0
3 months ago
Other questions:
  • Write a sequence of statements that create a file named "greeting" and write a single line consisting of "Hello, World!" to that
    5·1 answer
  • How concerned are you about the security of rtos in cars smart homes and wearable technology?
    15·1 answer
  • Sara is writing a program to input her monthly phone bills and output the month name and amount for the month with maximum amoun
    7·1 answer
  • Language levels have a direct influence on _______________
    10·1 answer
  • A competitor goes to your public website and discovers that they can get into a directory that you did not know could be reached
    10·1 answer
  • Kylee needs to ensure that if a particular client sends her an email while she is on vacation, the email is forwarded to a
    10·1 answer
  • A _________ level breach of security could cause a significant degradation in mission capability to an extent and duration that
    13·1 answer
  • Manipulate the SQL statement to pull ALL fields and rows from Customers table that have a PostalCode of 44000. TIP: Since Postal
    13·1 answer
  • Acme Parts runs a small factory and employs workers who are paid one of three hourly rates depending on their shift: first shift
    5·1 answer
  • 1A network administrator notices that some newly installed Ethernet cabling is carrying corrupt and distorted data signals. The
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!