C++ Program: Calculator to Add, Subtract, Multiply, and Divide two numbers using switch statement

By: Prof. Dr. Fazal Rehman | Last updated: July 13, 2024

Write a Simple program in C++ for Calculator to Add, Subtract, Multiply, and Divide two numbers.

Example Outputs:

Example Output #1

Enter operator (+, -, *, /): + Enter two numbers: 5 3 5 + 3 = 8

Example Output #2

Enter operator (+, -, *, /): – Enter two numbers: 10 4 10 – 4 = 6

Example Output #3

Enter operator (+, -, *, /): * Enter two numbers: 7 6 7 * 6 = 42

Example Output #4

Enter operator (+, -, *, /): / Enter two numbers: 8 2 8 / 2 = 4

Example Output #5

Enter operator (+, -, *, /): / Enter two numbers: 5 0 Error! Division by zero.

Example Output #6

Enter operator (+, -, *, /): & Enter two numbers: 4 2 Error! Operator is not correct.  

Memory Consumption for each variable

Variable Name Data Type Description Memory Consumption
op char Operator 1 byte
num1 double Operand 1 8 bytes
num2 double Operand 2 8 bytes
 
All Copyrights Reserved 2025 Reserved by T4Tutorials