mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 05:09:19 +00:00
error 3
This commit is contained in:
parent
56a07c5c4b
commit
b9022cfd1f
@ -16,7 +16,6 @@
|
|||||||
// There are at least two ways to implement this that are both correct-- but
|
// There are at least two ways to implement this that are both correct-- but
|
||||||
// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways.
|
// one is a lot shorter! Execute `rustlings hint errors2` for hints to both ways.
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
@ -24,8 +23,10 @@ pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
|||||||
let processing_fee = 1;
|
let processing_fee = 1;
|
||||||
let cost_per_item = 5;
|
let cost_per_item = 5;
|
||||||
let qty = item_quantity.parse::<i32>();
|
let qty = item_quantity.parse::<i32>();
|
||||||
|
match qty{
|
||||||
Ok(qty * cost_per_item + processing_fee)
|
Ok(qty)=> Ok(qty * cost_per_item + processing_fee),
|
||||||
|
Err(error)=> Err(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|||||||
@ -4,16 +4,18 @@
|
|||||||
// Why not? What should we do to fix it?
|
// Why not? What should we do to fix it?
|
||||||
// Execute `rustlings hint errors3` for hints!
|
// Execute `rustlings hint errors3` for hints!
|
||||||
|
|
||||||
// I AM NOT DONE
|
|
||||||
|
|
||||||
use std::num::ParseIntError;
|
use std::num::ParseIntError;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut tokens = 100;
|
let mut tokens = 100;
|
||||||
let pretend_user_input = "8";
|
let pretend_user_input = "a";
|
||||||
|
|
||||||
let cost = total_cost(pretend_user_input)?;
|
|
||||||
|
|
||||||
|
let cost = total_cost(pretend_user_input);
|
||||||
|
let cost= match cost {
|
||||||
|
Ok(cost)=>cost,
|
||||||
|
Err(err)=>err
|
||||||
|
};
|
||||||
if cost > tokens {
|
if cost > tokens {
|
||||||
println!("You can't afford that many!");
|
println!("You can't afford that many!");
|
||||||
} else {
|
} else {
|
||||||
@ -25,7 +27,9 @@ fn main() {
|
|||||||
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
pub fn total_cost(item_quantity: &str) -> Result<i32, ParseIntError> {
|
||||||
let processing_fee = 1;
|
let processing_fee = 1;
|
||||||
let cost_per_item = 5;
|
let cost_per_item = 5;
|
||||||
let qty = item_quantity.parse::<i32>()?;
|
let qty = item_quantity.parse::<i32>();
|
||||||
|
match qty{
|
||||||
Ok(qty * cost_per_item + processing_fee)
|
Ok(qty)=> Ok(qty * cost_per_item + processing_fee),
|
||||||
|
Err(error)=> Err(error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user