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;
}