A production-ready, deployable command-line calculator written in C. The application evaluates simple binary arithmetic expressions interactively or via command-line flags, with comprehensive error handling and automated tests.
- Evaluate addition, subtraction, multiplication, and division.
- Interactive REPL with prompts, exit commands, and helpful error messages.
- Non-interactive
--evalmode for scripting and automation. - Configurable output precision and optional quiet mode for cleaner pipelines.
- Cross-platform friendly build using a simple
Makefile. - Automated unit tests covering parsing, computation, and error scenarios.
- POSIX-like environment (macOS, Linux, or Windows with a POSIX toolchain).
- A C11 compatible compiler (e.g.
gcc,clang). - Standard development utilities:
make,install.
make buildThe compiled binary is placed in build/calculator.
Run the test suite with:
make testAll tests must pass before deploying.
Start the interactive shell:
./build/calculatorEvaluate a single expression:
./build/calculator --eval "12 / 4"Adjust the displayed precision (between 1 and 15 significant digits):
./build/calculator --precision 6 --eval "10 / 3"Disable the interactive prompt to better support pipelines:
echo "3 + 4" | ./build/calculator --no-promptShow all available flags:
./build/calculator --helpInstall the binary into /usr/local/bin (override PREFIX or DESTDIR as
needed):
sudo make installUninstall:
sudo make uninstall- Run
make clean && make buildto ensure a fresh build succeeds. - Run
make testand confirm all tests pass. - Package and distribute
build/calculator, or deploy viamake install. - Provide this README to operators for runbook reference.
This project is provided as-is without any specific license; adapt it to your organisation's licensing requirements as needed.