summaryrefslogtreecommitdiff
path: root/02/circumference.rs
diff options
context:
space:
mode:
authorAdam T. Carpenter <atc@53hor.net>2023-07-17 22:44:41 -0400
committerAdam T. Carpenter <atc@53hor.net>2023-07-17 22:44:41 -0400
commit738d22188695226cf1d9efe47da4114f43da1b93 (patch)
tree6684af3efd4e4d58a22fcad374759e09143bb4c0 /02/circumference.rs
parentcbfbfcf897552f3f162572d6c3fa50b84e26e3e1 (diff)
downloadcps-rust-master.tar.xz
cps-rust-master.zip
feat: begin chapter 2HEADmaster
Diffstat (limited to '02/circumference.rs')
-rw-r--r--02/circumference.rs20
1 files changed, 20 insertions, 0 deletions
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}.");
+}