2 releases
0.1.1 | Oct 22, 2024 |
---|---|
0.1.0 | Oct 22, 2024 |
#166 in Math
11KB
212 lines
Rust Command-Line Calculator
Description
This project is a simple yet powerful command-line calculator implemented in Rust. It provides basic arithmetic operations but will add more in the future. The calculator includes a history feature to track and review past calculations, with the ability to download this history to a file.
Features
- Basic arithmetic operations: addition, subtraction, multiplication, and division
- Continuous calculation: apply operations to the previous result
- Clear function to reset the calculator
- Error handling for invalid inputs and division by zero
- Modular design for easy maintenance and extensibility
- History feature to track and review past calculations
- Option to clear calculation history
- Download calculation history to a file
Installation
From crates.io
The easiest way to install the Rust Calculator is via crates.io:
Make sure you have Rust and Cargo installed on your system. If not, you can install them from rustup.rs.
From source
To build and run the project from source:
- Ensure you have Rust and Cargo installed
- Clone the repository
- Navigate to the project directory
- Run
cargo build
to build the project - Run
cargo run
to start the calculator
How to Use
- After installation, run the program by typing
calc
in your terminal - Select an operation from the menu
- If there's no current result, enter two numbers
- If there's a current result, enter one number to apply the operation
- The result will be displayed, and you can continue with more operations
- Select 'history' to view past calculations
- Select 'download history' to save the calculation history to a file
- Select 'clear history' to erase the calculation history
- Select 'clear' to reset the calculator or 'exit' to quit the program
Downloading History
When you use the 'download history' command, a file named operations_history.txt
will be created in your current directory. This file contains a record of all calculations performed in the current session.
Project Structure
The project is organized into several modules:
main.rs
: The entry point of the application, handling the main loop and user interactioncalculator.rs
: Implements the core calculation logic and manages calculation historyinput.rs
: Manages user input handlingmenu.rs
: Provides a menu interface for operation selectionhistory.rs
: Defines structures and methods for managing calculation history
Dependencies
dialoguer
: For creating an interactive command-line menu
Future Improvements
- Add more complex mathematical operations
- Implement the ability to recall and reuse specific calculations from history
- Add support for parentheses and order of operations
License
This project is licensed under the MIT License.
Dependencies
~1.7–9MB
~83K SLoC