summaryrefslogtreecommitdiff
path: root/exercises/02_functions
diff options
context:
space:
mode:
authormo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
committermo8it <mo8it@proton.me>2024-07-05 13:39:50 +0200
commit7123c7ae3a9605fbe962e4ef0a0f1424cd16fef8 (patch)
treec67f7e62bb9a179ae4fdbab492501cb6847e64c7 /exercises/02_functions
parent77b687d501771c24bd83294d97b8e6f9ffa92d6b (diff)
parent4d9c346a173bb722b929f3ea3c00f84954483e24 (diff)
Merge remote-tracking branch 'upstream/main' into fix-enum-variant-inconsistency
Diffstat (limited to 'exercises/02_functions')
-rw-r--r--exercises/02_functions/functions1.rs9
-rw-r--r--exercises/02_functions/functions2.rs16
-rw-r--r--exercises/02_functions/functions3.rs16
-rw-r--r--exercises/02_functions/functions4.rs26
-rw-r--r--exercises/02_functions/functions5.rs16
5 files changed, 27 insertions, 56 deletions
diff --git a/exercises/02_functions/functions1.rs b/exercises/02_functions/functions1.rs
index 40ed9a0..a812c21 100644
--- a/exercises/02_functions/functions1.rs
+++ b/exercises/02_functions/functions1.rs
@@ -1,10 +1,5 @@
-// functions1.rs
-//
-// Execute `rustlings hint functions1` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
+// TODO: Add some function with the name `call_me` without arguments or a return value.
fn main() {
- call_me();
+ call_me(); // Don't change this line
}
diff --git a/exercises/02_functions/functions2.rs b/exercises/02_functions/functions2.rs
index 5154f34..2c773c6 100644
--- a/exercises/02_functions/functions2.rs
+++ b/exercises/02_functions/functions2.rs
@@ -1,16 +1,10 @@
-// functions2.rs
-//
-// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
-
-fn main() {
- call_me(3);
-}
-
+// TODO: Add the missing type of the argument `num` after the colon `:`.
fn call_me(num:) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}
}
+
+fn main() {
+ call_me(3);
+}
diff --git a/exercises/02_functions/functions3.rs b/exercises/02_functions/functions3.rs
index 74f44d6..5d5122a 100644
--- a/exercises/02_functions/functions3.rs
+++ b/exercises/02_functions/functions3.rs
@@ -1,16 +1,10 @@
-// functions3.rs
-//
-// Execute `rustlings hint functions3` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
-
-fn main() {
- call_me();
-}
-
fn call_me(num: u32) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}
}
+
+fn main() {
+ // TODO: Fix the function call.
+ call_me();
+}
diff --git a/exercises/02_functions/functions4.rs b/exercises/02_functions/functions4.rs
index 77c4b2a..b22bffd 100644
--- a/exercises/02_functions/functions4.rs
+++ b/exercises/02_functions/functions4.rs
@@ -1,21 +1,14 @@
-// functions4.rs
-//
// This store is having a sale where if the price is an even number, you get 10
-// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. (Don't worry
-// about the function bodies themselves, we're only interested in the signatures
-// for now. If anything, this is a good way to peek ahead to future exercises!)
-//
-// Execute `rustlings hint functions4` or use the `hint` watch subcommand for a
-// hint.
+// Rustbucks off, but if it's an odd number, it's 3 Rustbucks off.
+// Don't worry about the function bodies themselves, we are only interested in
+// the signatures for now.
-// I AM NOT DONE
-
-fn main() {
- let original_price = 51;
- println!("Your sale price is {}", sale_price(original_price));
+fn is_even(num: i64) -> bool {
+ num % 2 == 0
}
-fn sale_price(price: i32) -> {
+// TODO: Fix the function signature.
+fn sale_price(price: i64) -> {
if is_even(price) {
price - 10
} else {
@@ -23,6 +16,7 @@ fn sale_price(price: i32) -> {
}
}
-fn is_even(num: i32) -> bool {
- num % 2 == 0
+fn main() {
+ let original_price = 51;
+ println!("Your sale price is {}", sale_price(original_price));
}
diff --git a/exercises/02_functions/functions5.rs b/exercises/02_functions/functions5.rs
index f1b63f4..34a2ac7 100644
--- a/exercises/02_functions/functions5.rs
+++ b/exercises/02_functions/functions5.rs
@@ -1,15 +1,9 @@
-// functions5.rs
-//
-// Execute `rustlings hint functions5` or use the `hint` watch subcommand for a
-// hint.
-
-// I AM NOT DONE
+// TODO: Fix the function body without changing the signature.
+fn square(num: i32) -> i32 {
+ num * num;
+}
fn main() {
let answer = square(3);
- println!("The square of 3 is {}", answer);
-}
-
-fn square(num: i32) -> i32 {
- num * num;
+ println!("The square of 3 is {answer}");
}