1
0
mirror of https://github.com/rust-lang/rustlings.git synced 2025-12-11 23:27:23 +02:00

Just remembered another function one I wanted to do

This commit is contained in:
Carol (Nichols || Goulding)
2015-09-18 20:28:27 -04:00
parent 9336aed2b9
commit 36a75c733e
2 changed files with 44 additions and 0 deletions

43
functions/functions5.rs Normal file
View File

@@ -0,0 +1,43 @@
// 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...