Skip to content
Related Articles

Related Articles

C/C++ program to make a simple calculator

View Discussion
Improve Article
Save Article
  • Difficulty Level : Easy
  • Last Updated : 22 Nov, 2018
View Discussion
Improve Article
Save Article

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.


// C++ program to create calculator using
// switch statement
#include <iostream>
using namespace std;
// Main program
    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;
        // If user enter - 
        case '-':
            cout << num1 - num2;
        // If user enter *
        case '*':
            cout << num1 * num2;
        // If user enter /
        case '/':
            cout << num1 / num2;
        // If the operator is other than +, -, * or /, 
        // error message will display
            cout << "Error! operator is not correct";
    } // switch statement ends
    return 0; 


  • Click on the run ide button, another tab will be open with web address
  • 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

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!