summaryrefslogtreecommitdiff
path: root/02/circumference.rs
blob: a27da4406c63c1562d08a8b1b17f1b550609e08c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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}.");
}