“Code is for computers. Output is for humans.”
Many beginners think “printing to the screen” is trivial.
In reality, output is the first handshake between your code and the real world — the first moment your logic turns into experience.
A well-formatted output is not about aesthetics; it’s about clarity, respect, and precision.
Here’s how even a simple BMI result can go from plain to professional, and finally to wow.
4.1 The Goal
After validating input and computing BMI, we want to:
- Show numbers with controlled precision.
- Provide a clear, human interpretation (underweight, normal, overweight, obesity).
- Avoid raw or cluttered text like
BMI=24.137245. - Make users feel they’re using a tool built with care, not a quick demo.
4.2 Common Helpers
fn interpret_bmi(bmi: f64) -> &'static str {
match bmi {
x if x < 18.5 => "Underweight – consider healthy nutrition and medical advice.",
x if x < 25.0 => "Normal weight – maintain your healthy habits.",
x if x < 30.0 => "Overweight – balance diet and activity for better health.",
_ => "Obesity – consult a doctor for a tailored health plan.",
}
}
fn category_label(bmi: f64) -> &'static str {
match bmi {
x if x < 18.5 => "Underweight",
x if x < 25.0 => "Normal",
x if x < 30.0 => "Overweight",
_ => "Obesity",
}
}
// Simple formatting shortcuts
fn fmt2(x: f64) -> String { format!("{:.2}", x) }
fn fmt1(x: f64) -> String { format!("{:.1}", x) }
4.3 Version 1 – The Honest and Raw Approach
fn print_basic(height_m: f64, weight_kg: f64, bmi: f64) {
println!("Your BMI is {}", fmt2(bmi));
println!("Category: {}", category_label(bmi));
println!("Height: {} m, Weight: {} kg", fmt2(height_m), fmt1(weight_kg));
}
Output:
Your BMI is 22.20
Category: Normal
Height: 1.75 m, Weight: 68.0 kg
What it teaches:
✅ It works.
❌ But there’s no structure, no guidance for the eye, no feeling of completeness.
4.4 Version 2 – The Structured and Clear Style
fn print_curated(height_m: f64, weight_kg: f64, bmi: f64) {
println!("\n==============================");
println!(" BMI RESULT");
println!("==============================");
println!("Height : {} m", fmt2(height_m));
println!("Weight : {} kg", fmt1(weight_kg));
println!("------------------------------");
println!("BMI : {}", fmt2(bmi));
println!("Status : {}", category_label(bmi));
println!("Note : {}", interpret_bmi(bmi));
println!("==============================\n");
}
Output:
==============================
BMI RESULT
==============================
Height : 1.75 m
Weight : 68.0 kg
------------------------------
BMI : 22.20
Status : Normal
Note : Normal weight – maintain your healthy habits.
==============================
Why it matters:
The difference is tone. This looks intentional — something a professional would hand to a client.
Structure builds trust.
4.5 Version 3 – The Elegant, Respectful Presentation
Here’s where “WoW” happens: the same data, but communicated beautifully.
fn print_elegant(height_m: f64, weight_kg: f64, bmi: f64) {
let use_color = std::env::var("NO_COLOR").is_err(); // disable if NO_COLOR is set
let (reset, dim, strong, ok, warn, alert) = if use_color {
("\x1b[0m", "\x1b[2m", "\x1b[1m", "\x1b[32m", "\x1b[33m", "\x1b[31m")
} else {
("", "", "", "", "", "")
};
let status = category_label(bmi);
let status_colored = match status {
"Normal" => format!("{ok}{status}{reset}"),
"Underweight" => format!("{warn}{status}{reset}"),
"Overweight" => format!("{warn}{status}{reset}"),
"Obesity" => format!("{alert}{status}{reset}"),
_ => status.to_string(),
};
let h = fmt2(height_m);
let w = fmt1(weight_kg);
let b = fmt2(bmi);
let title = format!("{strong}BMI SUMMARY{reset}");
let ranges = format!(
"{dim}Ranges → Under: <18.5 | Normal: 18.5–24.9 | Over: 25–29.9 | Obesity: ≥30{reset}"
);
let top = "┌───────────────────────────────────────────┐";
let mid = "├───────────────────────────────────────────┤";
let bottom = "└───────────────────────────────────────────┘";
println!();
println!("{top}");
println!("│ {:^41} │", title);
println!("{mid}");
println!("│ {:<12} {:>26} │", "Height:", format!("{h} m"));
println!("│ {:<12} {:>26} │", "Weight:", format!("{w} kg"));
println!("│ {:<12} {:>26} │", "BMI:", b);
println!("│ {:<12} {:>26} │", "Status:", status_colored);
println!("{mid}");
println!("│ {:<41} │", ranges);
println!("{bottom}");
println!();
}
Output:
┌───────────────────────────────────────────┐
│ BMI SUMMARY │
├───────────────────────────────────────────┤
│ Height: 1.75 m │
│ Weight: 68.0 kg │
│ BMI: 22.20 │
│ Status: Normal │
├───────────────────────────────────────────┤
│ Ranges → Under: <18.5 | Normal: 18.5–24.9 │
│ Over: 25–29.9| Obesity: ≥30 │
└───────────────────────────────────────────┘
(“Normal” appears in green; warnings and obesity appear in yellow/red depending on category.)
Why it’s “WoW”:
- Visual hierarchy, alignment, and proportional spacing.
- Optional ANSI colors used tastefully — clarity, not decoration.
- Context line showing BMI ranges makes the output self-explanatory.
- Same math, but the communication is now deliberate, precise, and kind.
4.6 Quick Test
fn main() {
let height_m = 1.75;
let weight_kg = 68.0;
let bmi = weight_kg / (height_m * height_m);
print_basic(height_m, weight_kg, bmi);
print_curated(height_m, weight_kg, bmi);
print_elegant(height_m, weight_kg, bmi);
}
4.7 The Essence of “WoW”
The numerical result never changed — but the emotional impact did.
Good design in code is about intentional communication.
Formatting is not decoration; it’s part of the user’s trust contract.
Precision is kindness.
Every line break, every decimal, every alignment says something about how much you care — not just about the program, but about the person using it.
When a beginner sees their terminal print something elegant, readable, and human, that’s the moment of WoW.
That’s when coding stops feeling mechanical and starts feeling meaningful.
From Zero to WoW – Rust Edition
Small code, big principles. The elegance is in how you treat simplicity.
