Create Basic Calculator in C++ Language with Free Codes

Intro

Hey, Here you get Free Codes of Basic Calculator which is made with a C++ Language to boost the logic skill of beginners. This Calculator Project is mainly used for perform the basic calculations like, addition, subtraction, multiplication and division.

Codes

#include <iostream>
using namespace std;

int main() {
    char operation;
    double num1, num2;

    // Display available operations
    cout << "Select an operation to perform (+, -, *, /): ";
    cin >> operation;

    // Input two numbers
    cout << "Enter two numbers: ";
    cin >> num1 >> num2;

    // Perform the chosen operation
    switch(operation) {
        case '+':
            cout << "Result: " << num1 + num2 << endl;
            break;
        case '-':
            cout << "Result: " << num1 - num2 << endl;
            break;
        case '*':
            cout << "Result: " << num1 * num2 << endl;
            break;
        case '/':
            if(num2 != 0)
                cout << "Result: " << num1 / num2 << endl;
            else
                cout << "Error: Division by zero!" << endl;
            break;
        default:
            cout << "Error: Invalid operation!" << endl;
            break;
    }

    return 0;
}

C++ Learning Material

  1. C++ Free Course: – Here You also get C++ Language Free Course – Tap on Me.
  2. C++ Cheat-Sheet:- For Quick Preparation for exams and interviews – Tap on Me.
  3. C++ Free Notes: – For College Purpose – Tap on Me.
Basic Calculator  - Quiz

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top