C/C++ program to make a simple calculator

Calculators are widely used device nowadays. It makes calculations easier and faster. Calculators are used to everyone in daily life. A simple calculator can be made using a C++ program which is able to add, subtract, multiply and divide, two operands entered by the user. The switch and break statement is used to create a calculator.
Program:
// C++ program to create calculator using // switch statement #include <iostream> using namespace std; // Main program main() { char op; float num1, num2; // It allows user to enter operator i.e. +, -, *, / cin >> op; // It allow user to enter the operands cin >> num1 >> num2; // Switch statement begins switch (op) { // If user enter + case '+': cout << num1 + num2; break; // If user enter - case '-': cout << num1 - num2; break; // If user enter * case '*': cout << num1 * num2; break; // If user enter / case '/': cout << num1 / num2; break; // If the operator is other than +, -, * or /, // error message will display default: cout << "Error! operator is not correct"; break; } // switch statement ends return 0; } |
chevron_right
filter_none
Output:
- Click on the run ide button, another tab will be open with web address
“https://ide.geeksforgeeks.org/index.php”

- Put the input in the input box
- Enter the arithmetic operator (i.e.: either +, -, * or /) then, enter two operands on which need to perform the calculation
- Click on the run button
- Then output box will appear with output
Recommended Posts:
- Menu Driven C++ Program for a Simple Calculator
- Program for EMI Calculator
- Basic calculator program using Python
- Program to create grade calculator in Python
- Program to find simple interest
- Python | Program to implement simple FLAMES game
- Program to make a histogram of an array
- Dockerizing a simple Nodejs app
- Array implementation of queue (Simple)
- Kruskal's Algorithm (Simple Implementation for Adjacency Matrix)
- Prim's Algorithm (Simple Implementation for Adjacency Matrix Representation)
- Times required by Simple interest for the Principal to become Y times itself
- How to make a redirect in PHP?
- Do you want to make your own games?
- How to make div not larger than its contents using CSS?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



