A robust, modular command-line calculator implemented in C. This project is designed to demonstrate clean code architecture, header-source separation, and advanced mathematical error handling.
- Arithmetic: Basic operations (+, -, *, /, %) with operator precedence.
- Advanced Math: Power, Square Root, and Logarithm (base 10).
- Trigonometry: Sine, Cosine, Tangent, and their inverse functions (with automatic Degree/Radian conversion).
- Robust Error Handling: Division-by-zero protection, negative input sanitization for square roots/logs, and modular input validation.
This repository uses GitHub Actions to automate the build and testing process on every push to the main branch.
- Automatic Compilation: The code is compiled using
gccwith-Wallto ensure no warnings or errors exist. - Automated Testing: The program is executed automatically to verify stability and check for runtime errors.
- Build Status: Check the badge at the top of the repository or visit the Actions tab to see live build logs.
| File | Description |
|---|---|
main.c |
Contains the main driver code and the interactive menu system. |
help.c |
Implementation of all arithmetic, trigonometric, and math logic. |
help.h |
Header file containing function declarations and operator enums. |
CMakeLists.txt |
Configuration file for building the project using CMake. |
- Language: C (Standard C11)
- Build System: CMake
- Architecture: Modular design (
main.c,help.c,help.h) - Input Handling: Secure usage of
fgetsandscanffor crash-proof CLI interactions.
- Ensure you have a C compiler (GCC/Clang) and CMake installed.
git clone https://github.com/TScom-dew/calculatorProgram-using-c.git
cd calculatorProgram-using-cmkdir build && cd build
cmake ..
cmake --build .
./calculator # On Linux/macOS
.\calculator # On Windows
This project was developed to practice:
- Modular Programming: Separating logic into header and source files for clean maintainability.
- Build Automation: Leveraging CMake for platform-independent compilation.
- Defensive Coding: Writing secure CLI applications that handle unexpected user input gracefully.
Contributions are welcome! If you have ideas for new features or improvements, feel free to fork this repository and submit a pull request.
Made with ❤️ by TScom-dew
Happy Coding! ❤️