A small command-line calculator built in C++ for practicing variables, user input, arithmetic operators, and switch statements.
The program reads two whole numbers and one arithmetic operator, performs the selected calculation through a switch statement, and prints the result.
This is a focused beginner project rather than a scientific calculator. The code is kept in one source file so the control flow is easy to follow while learning C++.
| Feature | Details |
|---|---|
| Addition | Adds two numbers with + |
| Subtraction | Subtracts the second number from the first with - |
| Multiplication | Multiplies two numbers with * |
| Division | Divides the first number by the second with / |
| Modulus | Finds the remainder for whole numbers with % |
| Code style | Calculation logic is handled with one switch statement |
Calculator-Cpp/
├── calculator.cpp # Main calculator program
├── .gitignore # Local build files excluded from Git
└── README.md # Project documentation
This project was created and tested in Dev-C++. The implementation intentionally uses only the input/output stream library and a simple switch-based structure:
#include<iostream>
using namespace std;No external packages or third-party dependencies are required.
Open calculator.cpp in Dev-C++, then choose Execute → Compile & Run. You can also press F11 to compile and run the program. Enter two numbers and an operator when the program asks for them.
=== C++ Calculator ===
Supported operators: + - * / %
The modulus operator works with whole numbers only.
Enter first number: 12.5
Enter an operator: *
Enter second number: 2
Result: 25
The program keeps all calculation logic in main() and uses one switch statement to select the requested operation. This straightforward structure is suitable for practicing beginner C++ fundamentals.
This project is available for learning and educational use.