mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
using MATCH AND ELSE
This commit is contained in:
parent
938bf326df
commit
6c2f6772e6
@ -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<i32, ParseIntError> {
|
||||
let processing_fee = 1;
|
||||
let cost_per_item = 5;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user