https://github.com/ilukemagic/rust-calculator-cli
A simple command-line calculator application written in Rust that supports basic arithmetic operations.
https://github.com/ilukemagic/rust-calculator-cli
Last synced: 5 months ago
JSON representation
A simple command-line calculator application written in Rust that supports basic arithmetic operations.
- Host: GitHub
- URL: https://github.com/ilukemagic/rust-calculator-cli
- Owner: ilukemagic
- Created: 2025-03-13T14:09:31.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-03-14T10:18:45.000Z (12 months ago)
- Last Synced: 2025-07-01T05:04:51.109Z (8 months ago)
- Language: Rust
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Rust Calculator CLI
A simple command-line calculator application written in Rust that supports basic arithmetic operations.
## Features
- Interactive command-line interface
- Supports basic arithmetic operations:
- Addition (+)
- Subtraction (-)
- Multiplication (\*)
- Division (/)
- Error handling for invalid inputs
- Follows order of operations (multiplication and division before addition and subtraction)
## Installation
### Prerequisites
- Rust and Cargo (install from [https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install))
### Building from Source
1. Clone the repository:
```
git clone https://github.com/yourusername/rust-calculator-cli.git
cd rust-calculator-cli
```
2. Build the project:
```
cargo build --release
```
3. Run the calculator:
```
cargo run --release
```
## Usage
After starting the application, you'll see a prompt where you can enter mathematical expressions:
```
Welcome to the Rust Calculator!
Enter 'quit' to exit.
> 2 + 3
Tokens: [Number(2.0), Plus, Number(3.0)]
Result: 5
> 10 * 5 - 8
Tokens: [Number(10.0), Multiply, Number(5.0), Minus, Number(8.0)]
Result: 42
> quit
```
### Supported Operations
- Addition: `a + b`
- Subtraction: `a - b`
- Multiplication: `a * b`
- Division: `a / b`
The calculator follows the standard order of operations (multiplication and division before addition and subtraction).
## Project Structure
- `src/main.rs`: Contains all the calculator logic including tokenization, parsing, and evaluation
## Development
### Building and Testing
```
# Build the project
cargo build
# Run the tests
cargo test
# Run the application
cargo run
```
## License
This project is open source and available under the [MIT License](LICENSE).