Add a bit about the program for the users, fix spelling errors

This commit is contained in:
James Musselman 2024-03-14 17:52:22 -05:00
parent 1bf7e1a884
commit a27215ca56
Signed by: Musselman
GPG key ID: 1DAEFF35ECB5D6DB

View file

@ -3,12 +3,12 @@ Written by: James Musselman
On: 3/14/2024 On: 3/14/2024
Updated: Never Updated: Never
Description: Description:
This tool was writen as part of my 100DaysOfCode commitment for the 2024 year to help establish a This tool was written as part of my 100DaysOfCode commitment for the 2024 year to help establish a
habit of programming daily and fuel my continious drive to learn. habit of programming daily and fuel my continuous drive to learn.
The tool below should allow the user to run basic, intermediate, and advanced math computations. The tool below should allow the user to run basic, intermediate, and advanced math computations.
The user will select the equation or type of math they want to be done, enter the data, and The user will select the equation or type of math they want to be done, enter the data, and
then recive the result of the computation. then receive the result of the computation.
Future work could include showing how the answer was calculated, showing graphs, and exporting to Future work could include showing how the answer was calculated, showing graphs, and exporting to
a text file. a text file.
@ -16,15 +16,17 @@ Description:
*/ */
use std::io; use std::io;
fn main() { fn main() {
// TODO: Greet and explain tool // TODO: Greet and explain tool
println!("This math tool was made as a way to practice rust and is under development and does");
println!("not test or account for edge cases. (Go and try to divide by zero if you want to...0)\n");
println!("To use the tool enter a number from the menu below and enter values as requested.");
println!("If the number you enter does not exist in the menu it will be the return value.\n");
// Get user choice on what they want to use // Get user choice on what they want to use
loop { loop {
//Print choices //Print choices
println!("Here are the current math tools:\n"); println!("Here are the current math tools:\n");
println!("1. Additon"); println!("1. Addition");
println!("2. Subtraction"); println!("2. Subtraction");
println!("3. Multiplication"); println!("3. Multiplication");
println!("4. Division"); println!("4. Division");
@ -34,7 +36,8 @@ fn main() {
println!("Please select a function above or use 'q' to quit:"); println!("Please select a function above or use 'q' to quit:");
io::stdin().read_line(&mut user_input) io::stdin()
.read_line(&mut user_input)
.expect("Failed to read line"); .expect("Failed to read line");
if user_input.trim().eq_ignore_ascii_case("q") { if user_input.trim().eq_ignore_ascii_case("q") {
@ -55,15 +58,18 @@ fn main() {
} }
fn run_function(num: i32) -> i32 { fn run_function(num: i32) -> i32 {
// run choice, then ask again or quit if the user selects that option // run choice, then ask again or quit if the user selects that option
match num { match num {
1 => addition(), 1 => addition(),
2 => subtraction(), 2 => subtraction(),
3 => multiplacation(), 3 => multiplication(),
4 => division(), 4 => division(),
_ => { _ => {
println!("{} is not a valid selection, please select one of the options below", num); println!(
0 "{} is not a valid selection, please select one of the options below",
num
);
num
} }
} }
} }
@ -72,12 +78,16 @@ fn addition() -> i32 {
println!("Please enter the value of the first number:"); println!("Please enter the value of the first number:");
let mut x = String::new(); let mut x = String::new();
io::stdin().read_line(&mut x).expect("Failed to read x value"); io::stdin()
.read_line(&mut x)
.expect("Failed to read x value");
let x: i32 = x.trim().parse().expect("Failed to parse x value"); let x: i32 = x.trim().parse().expect("Failed to parse x value");
println!("Please enter the value of the second number:"); println!("Please enter the value of the second number:");
let mut y = String::new(); let mut y = String::new();
io::stdin().read_line(&mut y).expect("Failed to read y value"); io::stdin()
.read_line(&mut y)
.expect("Failed to read y value");
let y: i32 = y.trim().parse().expect("Failed to parse y value"); let y: i32 = y.trim().parse().expect("Failed to parse y value");
x + y x + y
@ -87,27 +97,35 @@ fn subtraction() -> i32 {
println!("Please enter the value of the first number:"); println!("Please enter the value of the first number:");
let mut x = String::new(); let mut x = String::new();
io::stdin().read_line(&mut x).expect("Failed to read x value"); io::stdin()
.read_line(&mut x)
.expect("Failed to read x value");
let x: i32 = x.trim().parse().expect("Failed to parse x value"); let x: i32 = x.trim().parse().expect("Failed to parse x value");
println!("Please enter the value of the second number:"); println!("Please enter the value of the second number:");
let mut y = String::new(); let mut y = String::new();
io::stdin().read_line(&mut y).expect("Failed to read y value"); io::stdin()
.read_line(&mut y)
.expect("Failed to read y value");
let y: i32 = y.trim().parse().expect("Failed to parse y value"); let y: i32 = y.trim().parse().expect("Failed to parse y value");
x - y x - y
} }
fn multiplacation() -> i32 { fn multiplication() -> i32 {
println!("Please enter the value of the first number:"); println!("Please enter the value of the first number:");
let mut x = String::new(); let mut x = String::new();
io::stdin().read_line(&mut x).expect("Failed to read x value"); io::stdin()
.read_line(&mut x)
.expect("Failed to read x value");
let x: i32 = x.trim().parse().expect("Failed to parse x value"); let x: i32 = x.trim().parse().expect("Failed to parse x value");
println!("Please enter the value of the second number:"); println!("Please enter the value of the second number:");
let mut y = String::new(); let mut y = String::new();
io::stdin().read_line(&mut y).expect("Failed to read y value"); io::stdin()
.read_line(&mut y)
.expect("Failed to read y value");
let y: i32 = y.trim().parse().expect("Failed to parse y value"); let y: i32 = y.trim().parse().expect("Failed to parse y value");
x * y x * y
@ -117,12 +135,16 @@ fn division() -> i32 {
println!("Please enter the value of the first number:"); println!("Please enter the value of the first number:");
let mut x = String::new(); let mut x = String::new();
io::stdin().read_line(&mut x).expect("Failed to read x value"); io::stdin()
.read_line(&mut x)
.expect("Failed to read x value");
let x: i32 = x.trim().parse().expect("Failed to parse x value"); let x: i32 = x.trim().parse().expect("Failed to parse x value");
println!("Please enter the value of the second number:"); println!("Please enter the value of the second number:");
let mut y = String::new(); let mut y = String::new();
io::stdin().read_line(&mut y).expect("Failed to read y value"); io::stdin()
.read_line(&mut y)
.expect("Failed to read y value");
let y: i32 = y.trim().parse().expect("Failed to parse y value"); let y: i32 = y.trim().parse().expect("Failed to parse y value");
x / y x / y