Wrote program for Day 43

This commit is contained in:
Mariano Riefolo 2024-09-06 09:54:25 +02:00
parent 361017a754
commit 78c4cd6528
5 changed files with 72 additions and 1 deletions

View File

@ -89,7 +89,7 @@ We encourage you to share your progress and ask questions in the Discussions sec
| Day #40 | [Larrys Array](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-40_Larrys-Array) | :white_check_mark: | | Day #40 | [Larrys Array](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-40_Larrys-Array) | :white_check_mark: |
| Day #41 | [Sales By Match](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-41_Sales-By-Match) | :white_check_mark: | | Day #41 | [Sales By Match](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-41_Sales-By-Match) | :white_check_mark: |
| Day #42 | [Drawing Book](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-42_Drawing-Book) | :white_check_mark: | | Day #42 | [Drawing Book](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-06/Day-42_Drawing-Book) | :white_check_mark: |
| Day #43 | [Area Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-43_Area-Of-A-Triangle) | :white_large_square: | | Day #43 | [Area Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-43_Area-Of-A-Triangle) | :white_check_mark: |
| Day #44 | [Maximum Edge Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-44_Maximum-Edge-Of-A-Triangle) | :white_large_square: | | Day #44 | [Maximum Edge Of A Triangle](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-44_Maximum-Edge-Of-A-Triangle) | :white_large_square: |
| Day #45 | [Subtract The Swapped Bits...](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage) | :white_large_square: | | Day #45 | [Subtract The Swapped Bits...](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-45_Subtract-The-Swapped-Bits-Without-Temp-Storage) | :white_large_square: |
| Day #46 | [Hot Pics Of Danny Devito](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-46_Hot-Pics-Of-Danny-Devito) | :white_large_square: | | Day #46 | [Hot Pics Of Danny Devito](https://github.com/LiveGray/100-Days-Of-Rust/tree/main/Week-07/Day-46_Hot-Pics-Of-Danny-Devito) | :white_large_square: |

View File

@ -0,0 +1,6 @@
[package]
name = "day43"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

@ -0,0 +1,3 @@
pub fn tri_area(base: f64, height: f64) -> f64 {
base * height / 2f64
}

View File

@ -0,0 +1,28 @@
use std::{
io::{self, Write},
num::ParseFloatError,
};
use day43::tri_area;
fn read_f64(request: &str) -> Result<f64, ParseFloatError> {
let mut input = String::new();
print!("{}", request);
io::stdout().flush().expect("Failed to flush stdout");
std::io::stdin()
.read_line(&mut input)
.expect("Failed to read input");
input.trim().parse()
}
fn main() {
let base = read_f64("Enter the base of the triangle: ");
let height = read_f64("Enter the height of the triangle: ");
match base {
Ok(base) => match height {
Ok(height) => println!("The area of the triangle is: {}", tri_area(base, height)),
Err(e) => println!("Error: {}", e),
},
Err(e) => println!("Error: {}", e),
}
}

View File

@ -0,0 +1,34 @@
#[cfg(test)]
mod examples {
use day43::tri_area;
#[test]
fn example1() {
assert_eq!(tri_area(3f64, 2f64), 3f64);
}
#[test]
fn example2() {
assert_eq!(tri_area(5f64, 4f64), 10f64);
}
#[test]
fn example3() {
assert_eq!(tri_area(7f64, 4f64), 14f64);
}
#[test]
fn example4() {
assert_eq!(tri_area(10f64, 10f64), 50f64);
}
#[test]
fn example5() {
assert_eq!(tri_area(12f64, 11f64), 66f64);
}
#[test]
fn example6() {
assert_eq!(tri_area(0f64, 60f64), 0f64);
}
}