- C++ program to find factorial using recursive function
- C++ program to convert binary number to decimal and decimal to binary
- C++ program to display prime numbers between two intervals
- C++ program to print Pascal’s and Floyd’s triangle
- C++ program to print star pyramid patterns
- C++ Hello World Program
- C++ program to display Fibonacci series using loop and recursion
- C++ program to find area of the circle
- C++ program to calculate the area of the square with and without using function
- C++ program to encrypt and decrypt the string
- C++ program to convert temperature
- C++ program to check prime number
- C++ program to check palindrome number
- C++ program to make simple calculator using switch case
- C++ program for time conversion (convert time format)
- C++ program to find GCD or HCF
- C++ program to check for the power of two
- C++ program to check Armstrong number
- C++ program to check leap year
- C++ program to find LCM of two numbers

In this example, you will learn about C++ program to make simple calculator using switch case i.e. Addition, Subtraction, Multiplication, Squares, and Division.

This program uses 6 different cases for performing the different mathematical operation. You have to select different options for addition, subtraction, multiplication, square and division.

```
/* C++ program to implement simple functions of a calculator*/
#include<iostream>
using namespace std;
int main()
{
int choice;
long num1, num2, x;
//displaying different options
cout << "Please choose your option:"
"\n1 = Addition"
"\n2 = Subtraction"
"\n3 = Multiplication"
"\n4 = Division"
"\n5 = Squares"
"\n6 = exit"
"\n\nChoice: ";
cin >> choice;
//while loop check whether the choice is in the given range
while(choice < 1 || choice > 6)
{
cout << "\nPlease choose the above mentioned option."
"\nChoice: ";
cin >> choice;
}
switch (choice)
{
//Addition
case 1:
cout << "Enter two numbers: \n";
cin >> num1 >> num2;
x = num1 + num2;
cout << "Sum = " << x;
break;
//Subtraction
case 2:
cout << "Enter two numbers: \n";
cin >> num1 >> num2;
x = num1 - num2;
cout << "Subtraction = " << x;
break;
//Multiplication
case 3:
cout << "Enter two numbers: \n";
cin >> num1 >> num2;
x = num1 * num2;
cout << "Product = " << x;
break;
//Division
case 4:
cout << "Enter Dividend: ";
cin >> num1;
cout << "Enter Divisor: ";
cin >> num2;
//while loop checks for divisor whether it is zero or not
while(num2 == 0)
{
cout << "\nDivisor cannot be zero."
"\nEnter divisor once again: ";
cin >> num2;
}
x = num1 / num2;
cout << "\nQuotient = " << x;
break;
//Square
case 5:
cout << "Enter any number: \n";
cin >> num1;
x = num1 * num1;
cout << "Square = " << x;
break;
case 6:
return 0;
default: cout << "\nError";
}
}
```

**Output**

**Explanation**

In the above example, we have made a simple calculator in C++ with basic functions.

In a division, there is a special case to check whether divisor is zero.