In this post, we will write a C++ program to solve arithmetic operations. the first user will enter two values of the X and Y variable and then he will select the operation that he wants to perform like addition, subtraction, multiplication, and division. and then the program will print the desired output.
C++ program to solve arithmetic operations.
#include<iostream>
#include<conio.h>
int main()
{
int x,y,res;
char z;
std::cout<<"Enter the value of x = ";
std::cin>>x;
std::cout<<"Enter the value of y = ";
std::cin>>y;
std::cout<<"Enter the arithemtic operator like (+,-,* and /) = ";
std::cin>>z;
switch(z)
{
case '+':
res = x+y;
break;
case '-':
res = x-y;
break;
case '*':
res = x*y;
break;
case '/':
res = x/y;
break;
default:
std::cout<<"You do not press any operator";
}
std::cout<<"The result is = "<<res<<std::endl;
return 0;
}
Output
Enter the value of x = 6 Enter the value of y = 8 Enter the arithemtic operator like (+,-,* and /) = + The result is = 14