Respuesta :
Answer:
#include <iostream>
using namespace std;
int main()
{
//initialization
float x=0.0;
float y;
char operation;
//print the message
cout<<"Please enter the operation (Addition or Subtraction): ";
cin>>operation;
//loop for enter th operand again until enter 'q'
while(operation != 'q'){
//print the message for operand x
cout<<"\nPlease enter the operand x: ";
cin>>x;
//print the message for operand y
cout<<"\nPlease enter the operand y: ";
cin>>y;
//check for condition for '+' and if true then add the operands
if(operation == '+'){
x=x+y;
}else if(operation == '-'){ //if user enter '-' then subtract the operands
x=x-y;
}
//print the output
cout<<"\nThe output is: "<<x<<endl;
cout<<"\nPlease enter the operation (Addition or Subtraction): ";
cin>>operation;
}
return 0;
}
Explanation:
Create the main function and define the variable x equals zero and declare the variables y and operation.
print the message for the user to enter the operation ('+' or '-') by using the instruction cout.
Store the value in the variable by using the instruction cin.
Then, take the loop to repeat the statement again and again until the condition is true.
print the message inside the loop for asking about the operands from the user.
then, use condition statement for checking the operation and if condition match, then execute the particular operation.
The above operation executes until the user enters not enter the character 'q'.
when the user enters the 'q', the loop terminates and print the output.