diff options
Diffstat (limited to 'old_curriculum/functions/functions5.rs')
| -rw-r--r-- | old_curriculum/functions/functions5.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/old_curriculum/functions/functions5.rs b/old_curriculum/functions/functions5.rs new file mode 100644 index 0000000..f8fac5d --- /dev/null +++ b/old_curriculum/functions/functions5.rs @@ -0,0 +1,44 @@ +// functions5.rs +// Make me compile! Scroll down for hints :) + +fn main() { + let answer = square(3); + println!("The answer is {}", answer); +} + +fn square(num: i32) -> i32 { + num * num; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +// This is a really common error that can be fixed by removing one character. +// It happens because Rust distinguishes between expressions and statements: expressions return +// a value and statements don't. We want to return a value from the `square` function, but it +// isn't returning one right now... |
