A GUI-based calculator developed in C using GTK.
A beginner-friendly project developed as part of the CSE115 course in the Department of Electrical & Computer Engineering in North South University. This GUI-based calculator performs both basic arithmetic and scientific operations using the C programming language with a graphical interface powered by GTK.
c-gui-calculator/
โโโ main.c # Main code file to run the project
โโโ README.md # Project documentation
โโโ requirements.txt # List of required tools/libraries
โโโ .github/ # GitHub workflows and issue templates
โโโ .gitignore # Ignore unnecessary files
โโโ LICENSE # Project license
โโโ SECURITY.md # Security policy
โโโ _config.yml # Configuration file (for GitHub Pages)
โโโ data/ # Datasets (images, etc.)
โโโ support/ # Other code files
โโโ others/ # Final & update presentations, reports, and demo video
โ โโโ final_presentation.pptx
โ โโโ final_report.pdf
โ โโโ update_presentation.pptx
โ โโโ update_report.pdf
โ โโโ demo_video.mp4
sqrt(x) - calculates โx with domain validationlog(x) (base-10) and ln(x) (natural log)sin(x), cos(x), tan(x) - accepts degrees2 + 3 * 4 = 14 # Respects operator precedence
(2 + 3) * 4 = 20 # Parentheses override precedence
15 / 3 + 2 = 7 # Left-to-right evaluation for same precedence
50% = 0.5 # Percentage conversion
sqrt(16) = 4 # Square root
sqrt(2) = 1.414... # Works with non-perfect squares
log(100) = 2 # Base-10 logarithm
ln(2.718) = 1 # Natural logarithm (approximately e)
sin(30) = 0.5 # Sine in degrees
cos(60) = 0.5 # Cosine in degrees
tan(45) = 1 # Tangent in degrees
2^3 = 8 # Basic exponentiation
2^3^2 = 512 # Right associative: 2^(3^2), not (2^3)^2
(-2)^3 = -8 # Negative base with integer exponent
4^0.5 = 2 # Fractional exponents (same as sqrt)
sin(90) + sqrt(cos(0) * 4) = 3 # Mixed functions: 1 + sqrt(1 * 4) = 1 + 2 = 3
(5 + 3) * sqrt(16) / 2 = 16 # Multiple operations: 8 * 4 / 2 = 16
log(10^3) = 3 # Logarithm of power: log(1000) = 3
2 * sin(30) + cos(60) = 1.5 # Multiple trig functions: 2 * 0.5 + 0.5 = 1.5
| Key | Action | Description |
|---|---|---|
Enter |
Calculate | Same as pressing the = button |
Backspace |
Delete | Remove last character from input |
Numbers 0-9 |
Input | Use on-screen buttons only |
Operators |
Input | Use on-screen buttons only |
Note: Most input requires using the on-screen buttons to ensure proper token recognition by the expression parser.
The calculator provides comprehensive error checking for mathematical edge cases:
sqrt(-4) โ "Cannot take square root of negative number"
log(0) โ "Logarithm undefined for zero or negative numbers"
log(-5) โ "Logarithm undefined for zero or negative numbers"
ln(0) โ "Natural log undefined for zero or negative numbers"
5 / 0 โ "Division by zero"
1 / (2-2) โ "Division by zero"
0^(-2) โ "Cannot raise zero to negative power"
(-2)^1.5 โ "Cannot raise negative number to non-integer power"
(-3)^0.333 โ "Cannot raise negative number to non-integer power"
tan(90) โ "Tangent undefined at 90ยฐ and odd multiples"
tan(270) โ "Tangent undefined at 90ยฐ and odd multiples"
tan(-90) โ "Tangent undefined at 90ยฐ and odd multiples"
((2+3) โ "Mismatched parentheses"
2++) โ "Invalid character in expression"
sin( โ "Function 'sin' requires an argument"
+ * 2 โ "Not enough operands for operator"
This project was collaboratively developed by:
Ensure you have the following installed:
gcc (GNU Compiler Collection)pkg-config (Build configuration tool)libgtk-3-dev (GTK+ 3 development files)Clone the repository
git clone https://github.com/rafisarkar0128/c-gui-calculator.git
cd c-gui-calculator
Install dependencies
Linux (Ubuntu/Debian):
sudo apt update
sudo apt install gcc pkg-config libgtk-3-dev
Linux (Fedora/CentOS/RHEL):
sudo dnf install gcc pkgconf-pkg-config gtk3-devel
Windows (MSYS2):
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gtk3
macOS (Homebrew):
brew install gcc pkg-config gtk+3
Compile & Run
gcc -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
./calculator
๐ Need help? See our comprehensive Getting Started Guide for detailed setup instructions, troubleshooting tips, and platform-specific notes.
The calculator implements several advanced computer science concepts:
We welcome contributions! Hereโs how you can help:
For questions, bug reports, or contributions:
Thanks to our instructor and the CSE115 course staff for their guidance and resources, and to the open-source community for tools and inspiration.
This project is licensed under the MIT License.