Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Calculator Console

A console-based calculator built in C# that evaluates arithmetic expressions with support for operator precedence, calculation history, and robust error handling.

Features

  • 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

Technologies Used

  • C#
  • .NET (Console Application)

How to Run

  1. Clone the repository:
    git clone https://github.com/HedayatiNiaDev/Calculator-Console.git
  2. Open Calculator Console.slnx in Visual Studio (or your preferred .NET IDE).
  3. Build and run the project (F5 or dotnet run).

Usage

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 history
  • c — clear calculation history
  • e — exit the program

What I Learned

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

Status

Actively maintained as a personal practice project. Feedback and suggestions are welcome!


Author: Amir Mohammad Hedayati Nia

About

A console-based calculator built in C# that evaluates arithmetic expressions with support for operator precedence, calculation history, and robust error handling.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages