Skip to content

Commit fbb4fb1

Browse files
committed
02_basic_calculator/04_panics
1 parent 4c97106 commit fbb4fb1

File tree

1 file changed

+3
-0
lines changed
  • exercises/02_basic_calculator/04_panics/src

1 file changed

+3
-0
lines changed

exercises/02_basic_calculator/04_panics/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
/// calculate the average speed of the journey.
33
fn speed(start: u32, end: u32, time_elapsed: u32) -> u32 {
44
// TODO: Panic with a custom message if `time_elapsed` is 0
5+
if time_elapsed == 0 {
6+
panic!("The journey took no time at all. That's impossible!");
7+
}
58

69
(end - start) / time_elapsed
710
}

0 commit comments

Comments
 (0)