The goal of this project is to create a simple calculator that can perform basic arithmetic operations such as addition, subtraction, multiplication, and division. The calculator will be a command-line application written in Rust.
- Addition: The calculator should be able to add two numbers.
- Subtraction: The calculator should be able to subtract one number from another.
- Multiplication: The calculator should be able to multiply two numbers.
- Division: The calculator should be able to divide one number by another, with proper handling of division by zero.
- Input Handling: The calculator should accept user input for the operation and numbers.
- Output: The result of the calculation should be displayed to the user.
- Performance: The calculator should perform operations quickly and efficiently.
- Usability: The calculator should have a simple and intuitive command-line interface.
- Reliability: The calculator should handle errors gracefully, such as invalid input or division by zero.
- The application will be written in Rust.
- No external dependencies are required for this project.
- main.rs: The entry point of the application.
- calculator.rs: Contains the implementation of the calculator functionalities.
- Description: The entry point of the application. Handles user input and calls the appropriate calculator functions.
- Signature:
fn main()
- Description: Adds two numbers.
- Signature:
fn add(a: f64, b: f64) -> f64
- Description: Subtracts the second number from the first number.
- Signature:
fn subtract(a: f64, b: f64) -> f64
- Description: Multiplies two numbers.
- Signature:
fn multiply(a: f64, b: f64) -> f64
- Description: Divides the first number by the second number. Returns an error message if division by zero is attempted.
- Signature:
fn divide(a: f64, b: f64) -> Result<f64, &'static str>
- The user runs the program.
- The program prompts the user to enter the first number.
- The user enters the first number.
- The program prompts the user to enter the operation (+, -, *, /).
- The user enters the operation.
- The program prompts the user to enter the second number.
- The user enters the second number.
- The program performs the calculation and displays the result.
- The program prompts the user if they want to perform another calculation or exit.
- If the user enters an invalid number, the program should display an error message and prompt the user to enter the number again.
- If the user attempts to divide by zero, the program should display an error message and prompt the user to enter a valid divisor.