https://github.com/golgothaaksanti/cli-rust-calculator
A simple command-line calculator built with Rust. It supports basic arithmetic operations (+, -, *, /) and demonstrates user input handling, error handling, and clean control flow using Rustโs Result type.
https://github.com/golgothaaksanti/cli-rust-calculator
calculator calculator-app cli rust rust-lang
Last synced: 4 months ago
JSON representation
A simple command-line calculator built with Rust. It supports basic arithmetic operations (+, -, *, /) and demonstrates user input handling, error handling, and clean control flow using Rustโs Result type.
- Host: GitHub
- URL: https://github.com/golgothaaksanti/cli-rust-calculator
- Owner: GolgothaAksanti
- Created: 2025-06-07T14:59:15.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2025-06-07T15:14:12.000Z (4 months ago)
- Last Synced: 2025-06-07T16:28:15.653Z (4 months ago)
- Topics: calculator, calculator-app, cli, rust, rust-lang
- Language: Rust
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐งฎ Rust CLI Calculator
A simple and interactive command-line calculator built with Rust. This project is great for beginners learning Rust fundamentals like error handling, input/output, pattern matching, and basic control flow.
---
## โจ Features
- โ Supports addition (`+`), subtraction (`-`), multiplication (`*` or `x`), and division (`/`)
- ๐ซ Handles invalid input (e.g., text instead of numbers, divide by zero)
- ๐ Keeps prompting until valid input is received
- ๐ Great as a first Rust project---
## ๐ฆ Installation
Make sure you have Rust installed. If not:
```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh```
## Clone the repo and run
```bash
git clone https://github.com/GolgothaAksanti/cli-rust-calculator.git
cd cli-rust-calculator
cargo run```
## Example Usage
```bash
๐งฎ Rust CLI Calculator
Enter the first number: 12
Enter the second number: 4
Enter an operator (+, -, *, /): /
Result: 3```
handles errors gracefully:
```Bash
Enter the first number: hello
โ Invalid number. Please try again.Enter the second number: -
โ Invalid number. Please try again.Enter an operator (+, -, *, /): $
โ Invalid operator: $```
## ๐ง What You'll Learn
- How to read from `stdin` and print to `stdout`
- Using `.trim()`, `.parse::()`, and handling `Result` types
- Writing clean and idiomatic Rust for command-line tools
## Project Structure
```css
cli-rust-calculator/
โโโ src/
โ โโโ main.rs # Main calculator logic
โโโ Cargo.toml # Project manifest```
## ๐ค Contributing
Pull requests and suggestions are welcome! For major changes, please open an issue first to discuss what youโd like to change.
## ๐ก Bonus Ideas
- Add support for exponentiation (`^`)
- Support chaining multiple operations
- Build a history of calculations
- Add a GUI with `egui` or `gtk-rs`