A modular C command-line calculator supporting arithmetic, scientific functions, and robust error handling β perfect for learning C and CLI programming.

- Binary operations:
+
,-
,*
,/
,%
(remainder),**
(power) - Unary operations:
sqrt
,log
,ln
,abs
,cos
,sin
,tan
,exp
- Trigonometric inputs in degrees (converted internally to radians)
- Error handling with exit codes for invalid input, divide by zero, domain errors
- Smart output formatting (integers vs floats)
- Modular design for easy extension
# Binary (two operands)
./cli-calculator 10 + 5 # 15
./cli-calculator 2 ** 3 # 8
./cli-calculator 7 / 2 # 3.5
# Unary (single operand)
./cli-calculator sqrt 25 # 5
./cli-calculator log 1000 # 3
./cli-calculator cos 60 # 0.5
You can compile the project using either method:
# Using gcc directly
gcc -std=c11 -O2 -Wall -Wextra -lm -o cli-calculator calculator.c
# Or, if using the CS50 environment
make cli-calculator
0 β Success
1 β Invalid number of arguments
2 β Invalid operator or operation
3 β Division or modulo by zero
4 β Invalid number format
5 β Square root of negative number
6 β Log10 of non-positive number
7 β Natural log of non-positive number
8 β Tangent undefined (e.g., 90Β°, 270Β°, β¦)
This project is licensed under the MIT License. See the LICENSE file for details.