From 738d22188695226cf1d9efe47da4114f43da1b93 Mon Sep 17 00:00:00 2001 From: "Adam T. Carpenter" Date: Mon, 17 Jul 2023 22:44:41 -0400 Subject: feat: begin chapter 2 --- 02/circumference.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 02/circumference.rs (limited to '02/circumference.rs') diff --git a/02/circumference.rs b/02/circumference.rs new file mode 100644 index 0000000..a27da44 --- /dev/null +++ b/02/circumference.rs @@ -0,0 +1,20 @@ +use std::f64::consts::PI; +use std::io::stdin; + +/// Calculate the area and circumference of a circle from its radius. +/// 1. Prompt for a radius input. +/// 2. Parse the input into a numeric radius. +/// 3. Apply the area and circumference formulas. +/// 4. Print out the results. +fn main() { + let mut input = String::new(); + println!("Enter the radius of your circle: "); + stdin().read_line(&mut input).expect("No radius given."); + + let radius: f64 = input.trim().parse().expect("Invalid radius given."); + + let circumference = 2.0 * PI * radius; + let area = PI * radius.powi(2); + + println!("The circumference is: {circumference}, and the area is: {area}."); +} -- cgit v1.2.3