diff --git a/exercises/error_handling/errors3.rs b/exercises/error_handling/errors3.rs index a2d2d190..04c9be30 100644 --- a/exercises/error_handling/errors3.rs +++ b/exercises/error_handling/errors3.rs @@ -4,7 +4,7 @@ // Why not? What should we do to fix it? // Execute `rustlings hint errors3` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE + use std::num::ParseIntError; @@ -12,16 +12,24 @@ fn main() { let mut tokens = 100; let pretend_user_input = "8"; - let cost = total_cost(pretend_user_input)?; + //let cost = total_cost(pretend_user_input)?; - if cost > tokens { - println!("You can't afford that many!"); - } else { - tokens -= cost; - println!("You now have {} tokens.", tokens); + match total_cost(pretend_user_input) { + Ok(cost) => { + if cost > tokens { + println!("You can't afford that many!"); + } else { + tokens -= cost; + println!("You now have {} tokens.", tokens); + } + } + Err(err) => { + println!("Error: {}", err); + } } } + pub fn total_cost(item_quantity: &str) -> Result { let processing_fee = 1; let cost_per_item = 5;