Code is :
**************************************************************************************************************************************************
#include <iostream>
using namespace std;
int
main ()
{
double x, y;
//varible declaration of x and y
char oper;
//varible declaration of operator
cout << "Enter x:";
cin >> x;
//enter x
cout << "Enter y:";
cin >> y;
//enter y
while (y < 0)
{
//given if y < 0 invalid input and try
again
cout << "Illegal input" << endl;
cout << "Enter y:";
cin >> y;
}
cout << "Enter your operator:";
cin >> oper;
//enter operator
while (oper != '+' && oper != '-' && oper != '*'
&& oper != '/')
{
//if not valid try again
cout << "Invalid operator" << endl;
cout << "Enter your operator:";
cin >> oper;
}
if (oper == '+') //if + then
print a+b
cout << x + y;
if (oper == '-') //if - then
print a-b
cout << x - y;
if (oper == '*') //if * then
print a*b
cout << x * y;
if (oper == '/')//if / then print a/b
cout << x / y;
return 0;
}
*******************************************`******************************************************************************************************
Screenshot of code
Output:
Get Answers For Free
Most questions answered within 1 hours.