Loading repository data…
Loading repository data…
lakshaykamat / repository
A simple yet powerful command-line calculator written in C that supports basic arithmetic operations and advanced mathematical functions with a custom power implementation.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
A simple yet powerful command-line calculator written in C that supports basic arithmetic operations and advanced mathematical functions with a beautiful, colorful build system.
+): Add two numbers-): Subtract second number from first*): Multiply two numbers/): Divide first number by second^): Raise first number to the power of secondpow() function for accurate power calculationscalc command for global access-lm)Make sure you have a C compiler and Make installed on your system:
Ubuntu/Debian:
sudo apt update
sudo apt install build-essential make
macOS:
xcode-select --install
# Make is included with Xcode Command Line Tools
Windows: Install MinGW or use WSL (Windows Subsystem for Linux)
Clone or download the project files
Navigate to the project directory
cd cli-calculator
Build the program
make
Run the calculator
./bin/calculator
If you prefer to compile manually:
mkdir -p bin
gcc -Wall -Wextra -std=c99 -I./include -c src/calculator.c -o bin/calculator.o
gcc -Wall -Wextra -std=c99 -I./include -c src/main.c -o bin/main.o
gcc bin/calculator.o bin/main.o -o bin/calculator -lm
./bin/calculator
calc
The calculator accepts expressions in the format:
number1 operator number2
Examples:
5 + 3
10 - 4
6 * 7
15 / 3
2 ^ 3
| Operation | Symbol | Example | Result |
|---|---|---|---|
| Addition | + | 5 + 3 | 8.00 |
| Subtraction | - | 10 - 4 | 6.00 |
| Multiplication | * | 6 * 7 | 42.00 |
| Division | / | 15 / 3 | 5.00 |
| Power | ^ | 2 ^ 3 | 8.00 |
=== Simple CLI Calculator ===
Enter an expression (e.g., 5 + 2): 10 + 5
15.00
Do you want to perform another calculation? (y/n): y
Enter an expression (e.g., 5 + 2): 2 ^ 8
256.00
Do you want to perform another calculation? (y/n): n
Thank you for using the calculator!
The calculator uses the standard C math library pow() function for:
The calculator includes comprehensive error handling for:
cli-calculator/
├── src/ # Source files
│ ├── main.c # Main program logic and user interface
│ └── calculator.c # Mathematical operations implementation
├── include/ # Header files
│ └── calculator.h # Function declarations and constants
├── bin/ # Build output (gitignored)
│ ├── calculator # Compiled executable
│ ├── main.o # Object files
│ └── calculator.o # Object files
├── Makefile # Beautiful build configuration
├── .gitignore # Git ignore rules
└── README.md # This file
The project features a stunning, verbose Makefile with:
| Target | Description |
|---|---|
make or make all | Build the calculator (default) |
make clean | Remove build files |
make run | Build and run the calculator |
make install | Install as calc command |
make uninstall | Remove calc command |
make help | Show beautiful help message |
╔══════════════════════════════════════════════════════════════╗
║ COMPILING STAGE ║
╚══════════════════════════════════════════════════════════════╝
📝 Compiling source file: src/calculator.c
📦 Creating object file: bin/calculator.o
Command: gcc -Wall -Wextra -std=c99 -I./include -c src/calculator.c -o bin/calculator.o
✅ Compilation successful!
╔══════════════════════════════════════════════════════════════╗
║ LINKING STAGE ║
╚══════════════════════════════════════════════════════════════╝
🔗 Linking object files into executable...
Command: gcc bin/calculator.o bin/main.o -o bin/calculator -lm
╔══════════════════════════════════════════════════════════════╗
║ BUILD COMPLETE! ║
╚══════════════════════════════════════════════════════════════╝
✅ Calculator built successfully!
🚀 You can run it with: ./bin/calculator
# Build the calculator
make
# Clean build files
make clean
# Build and run
make run
# Install as 'calc' command (requires sudo)
make install
# Remove 'calc' command (requires sudo)
make uninstall
# Show beautiful help
make help
# Build and install
make install
After installation, you can use calc from anywhere:
# Run interactively
calc
# Use with pipes
echo "5 + 3" | calc
echo "2 ^ 8" | calc
# Test operations
echo -e "10 - 4\nn" | calc
echo -e "6 * 7\nn" | calc
echo -e "15 / 3\nn" | calc
make uninstall
# Basic operations
echo -e "5 + 3\nn" | ./bin/calculator
echo -e "10 - 4\nn" | ./bin/calculator
echo -e "6 * 7\nn" | ./bin/calculator
echo -e "15 / 3\nn" | ./bin/calculator
# Power operations
echo -e "2 ^ 3\nn" | ./bin/calculator
echo -e "4 ^ 0.5\nn" | ./bin/calculator
echo -e "2 ^ -2\nn" | ./bin/calculator
# Error handling
echo -e "5 / 0\nn" | ./bin/calculator
echo -e "invalid\nn" | ./bin/calculator
# Test the 'calc' command
echo -e "5 + 3\nn" | calc
echo -e "2 ^ 3\nn" | calc
echo -e "5 / 0\nn" | calc
1. Compilation Error: "command not found: gcc"
2. Make Error: "command not found: make"
3. Permission Denied Error
chmod +x bin/calculator
4. Input Not Working Properly
5. Build Fails with Include Errors
6. Math Library Linking Error
-lm flag for math library linking7. "calc: command not found" after installation
hash -r to refresh command cachePotential improvements for future versions:
This project is open source and available under the MIT License.
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions:
Happy Calculating! 🧮✨