Interactive Calculator
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 22 commits behind OwenHerndon:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Simple Interactive Calculator


Create a Console based Calculator in C#.


  • Everyone forks this repo (then clone your fork).
  • There should be Unit Tests on all classes and methods you create.
  • Your solution should have at least 2 total projects. Unit Tests should be in it's own project.
  • This is an OOP focused class. Therefore, there will be classes. Your Program class and Main method should only be responsible for receiving user input and printing output.
  • If a user submits an incomplete command or expression, the calculator should not attempt to evaluate it but print out a useful message.

Overview of how it should work

Starting your console application should create a prompt that looks like:


where x is the number of executed commands/expressions during the user's current session. Call this your "counter".

On startup, your initial prompt should always look like:


The user will enter simple mathematical expressions or commands. The user pressing [Enter] will have the calculator print out the correct answer on the following line (prefixed with an =). After the answer is printed, the user should return to the original prompt.

For example, below the user entered 2+1, then pressed [Enter]. The calculator printed out the answer 3 and reprinted the prompt, waiting for input from the user.

[0]> 2+1
   = 3

Further use of this session will again increment the counter part of the prompt:

[1]> 1-10
   = -9

Finally, typing exit or quit should exit the program while printing a message:

[2]> exit


Math Operations

Your calculator should following operations

  1. addition (integer)
  2. subtraction (integer)
  3. integer division (integer)
  4. modulus (integer)
  5. multiplication (integer)

Calculator Commands

In addition to math expressions, your calculator should accept the following commands:

  • quit and exit - exits the program
  • last - prints the last printed answer
  • lastq - prints the last entered command or expression


For the chosen few, you get the implement the concept of 'constants' in the caluculator. See below for how it should work:

[0]> x = 3
   = saved 'x' as '3'
[1]> x
   = 3
[2]> 1 + x
   = 4
[3]> x = 4
   = Error!

Constants Specifications

  1. Any lowercase letter of the alphabet can be a constant.
  2. Calculator should be case insensitive. A is considered the same as a.
  3. Constants can only be defined once per session.
  4. Defined constants can be used in math expressions
  5. Using undefined constants should result in a printed a helpful message noting the constant is undefined.


Read GUIDANCE for assistance on progressing through the project