Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Method

This code has a Circle struct with an area method, but the method is broken — it's missing &self so it can't access the circle's fields!

Fix the code so it prints:

text
Area: 78.5

Hint: Methods need &self as their first parameter so they can read the struct's fields.

rust
struct Circle {
radius: f64,
}

impl Circle {
fn area() -> f64 {
self.radius * self.radius * 3.14
}
}

fn main() {
let c = Circle { radius: 5.0 };
println!("Area: {}", c.area());
}