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
Mainmethod 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:
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.
> 2+1 = 3 >
Further use of this session will again increment the counter part of the prompt:
> 1-10 = -9 >
quit should exit the program while printing a message:
> exit Bye!!
Your calculator should following operations
- addition (integer)
- subtraction (integer)
- integer division (integer)
- modulus (integer)
- multiplication (integer)
In addition to math expressions, your calculator should accept the following commands:
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:
> x = 3 = saved 'x' as '3' > x = 3 > 1 + x = 4 > x = 4 = Error!
- Any lowercase letter of the alphabet can be a constant.
- Calculator should be case insensitive.
Ais considered the same as
- Constants can only be defined once per session.
- Defined constants can be used in math expressions
- Using undefined constants should result in a printed a helpful message noting the constant is undefined.