A console-based calculator built in C# that evaluates arithmetic expressions with support for operator precedence, calculation history, and robust error handling.
- Expression evaluation — supports full expressions in a single line (e.g.
10+20*30/40-200), not just single operations - Operator precedence — correctly applies
×/÷before+/-, following standard math rules - Multiple operator symbols — accepts both
*//and×/÷ - Negative numbers — handles negative numbers at the start of an expression or after an operator (e.g.
10*-20) - Calculation history — view (
h), and clear (c) a running history of past calculations, capped at 30 entries - Color-coded output — results shown in green, errors shown in red for quick readability
- Error handling — catches division by zero and invalid expressions, with example usage shown on invalid input
- C#
- .NET (Console Application)
- Clone the repository:
git clone https://github.com/HedayatiNiaDev/Calculator-Console.git
- Open
Calculator Console.slnxin Visual Studio (or your preferred .NET IDE). - Build and run the project (
F5ordotnet run).
On launch, enter an arithmetic expression directly:
Enter your operation(+,-,*,/): 10+20*30/40-200
10+20*30/40-200=-175
Other commands:
h— show calculation historyc— clear calculation historye— exit the program
This project was a hands-on exercise in:
- Parsing and evaluating mathematical expressions manually (without
eval-style shortcuts) - Implementing operator precedence logic from scratch
- Structuring a console application with clear separation of concerns (menu, calculation, history, error handling)
- Using exceptions for control flow around invalid input and edge cases like division by zero
Actively maintained as a personal practice project. Feedback and suggestions are welcome!
Author: Amir Mohammad Hedayati Nia