mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 21:29:18 +00:00
Complete functions 2,3,4
This commit is contained in:
parent
9978dd678f
commit
2a7fcefae0
@ -1,13 +1,11 @@
|
||||
// functions2.rs
|
||||
// Execute `rustlings hint functions2` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
call_me(3);
|
||||
}
|
||||
|
||||
fn call_me(num:) {
|
||||
fn call_me(num: i32) {
|
||||
for i in 0..num {
|
||||
println!("Ring! Call number {}", i + 1);
|
||||
}
|
||||
|
||||
@ -1,10 +1,8 @@
|
||||
// functions3.rs
|
||||
// Execute `rustlings hint functions3` or use the `hint` watch subcommand for a hint.
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
call_me();
|
||||
call_me(32);
|
||||
}
|
||||
|
||||
fn call_me(num: u32) {
|
||||
|
||||
@ -7,14 +7,12 @@
|
||||
// in the signatures for now. If anything, this is a good way to peek ahead
|
||||
// to future exercises!)
|
||||
|
||||
// I AM NOT DONE
|
||||
|
||||
fn main() {
|
||||
let original_price = 51;
|
||||
println!("Your sale price is {}", sale_price(original_price));
|
||||
}
|
||||
|
||||
fn sale_price(price: i32) -> {
|
||||
fn sale_price(price: u32) -> u32 {
|
||||
if is_even(price) {
|
||||
price - 10
|
||||
} else {
|
||||
@ -22,6 +20,6 @@ fn sale_price(price: i32) -> {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_even(num: i32) -> bool {
|
||||
fn is_even(num: u32) -> bool {
|
||||
num % 2 == 0
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user