Solution: Rectangle ARGS
examples/args/rectangle-args/src/main.rs
use std::env; use std::process::exit; fn main() { let args: Vec<String> = env::args().collect(); if args.len() != 3 { println!("Usage {} length width", args[0]); exit(1); } let width: i32 = args[1].parse().expect("Wanted a number"); let height: i32 = args[2].parse().expect("Wanted a number"); let area: i32 = width * height; let circumference = 2 * (width + height); println!("area: {area}"); println!("circumference: {circumference}"); }
cargo run Usage target/debug/rectangle-args length width
cargo run 3 4 area: 12 circumference: 14