Calculator in C++
#include <iostream>
int main()
{
int num1 ;
int num2 ;
char op ;
std::cout << "What would you like to do with two numbers (Give symbols like addition(+),substraction(-))";
std::cin >> op;
std::cout << "Enter first number : ";
std::cin >> num1;
std::cout << "Enter second number : ";
std::cin >> num2;
int result;
if (op == '+')
{
result = num1 + num2;
}
else if (op == '-')
{
result = num1 - num2;
}
else if (op == '*')
{
result = num1 * num2;
}
else if (op == '/')
{
result = num1 / num2;
}
else {
std::cout << "Invalid Operator";
}
std::cout << "Your answer is " << result ;
}
Comments
Post a Comment