Added my solutions to variables, functions and quiz1

This commit is contained in:
Rakshit Sinha 2021-07-05 15:54:35 -07:00
parent 84461c20cb
commit 3a64cde5ff
12 changed files with 20 additions and 33 deletions

View file

@ -1,8 +1,8 @@
// functions1.rs
// Make me compile! Execute `rustlings hint functions1` for hints :)
// I AM NOT DONE
fn main() {
call_me();
}
fn call_me() {}

View file

@ -1,13 +1,11 @@
// functions2.rs
// Make me compile! Execute `rustlings hint functions2` for hints :)
// I AM NOT DONE
fn main() {
call_me(3);
}
fn call_me(num:) {
fn call_me(num: i8) {
for i in 0..num {
println!("Ring! Call number {}", i + 1);
}

View file

@ -1,10 +1,9 @@
// functions3.rs
// Make me compile! Execute `rustlings hint functions3` for hints :)
// I AM NOT DONE
fn main() {
call_me();
let num: u32 = 3;
call_me(num);
}
fn call_me(num: u32) {

View file

@ -4,14 +4,12 @@
// 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.
// 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: i32) -> i32 {
if is_even(price) {
price - 10
} else {

View file

@ -1,13 +1,11 @@
// functions5.rs
// Make me compile! Execute `rustlings hint functions5` for hints :)
// I AM NOT DONE
fn main() {
let answer = square(3);
println!("The answer is {}", answer);
}
fn square(num: i32) -> i32 {
num * num;
num * num
}

View file

@ -10,7 +10,13 @@
// I AM NOT DONE
// Put your function here!
// fn ..... {
fn calculate_apple_price(quantity: i32) -> i32 {
if quantity < 40 {
quantity * 2
} else {
quantity
}
}
// Don't modify this function!
#[test]

View file

@ -6,9 +6,7 @@
// even after you already figured it out. If you got everything working and
// feel ready for the next exercise, remove the `I AM NOT DONE` comment below.
// I AM NOT DONE
fn main() {
x = 5;
let x = 5;
println!("x has the value {}", x);
}

View file

@ -1,10 +1,8 @@
// variables2.rs
// Make me compile! Execute the command `rustlings hint variables2` if you want a hint :)
// I AM NOT DONE
fn main() {
let x;
let x: i8 = 1;
if x == 10 {
println!("Ten!");
} else {

View file

@ -1,10 +1,8 @@
// variables3.rs
// Make me compile! Execute the command `rustlings hint variables3` if you want a hint :)
// I AM NOT DONE
fn main() {
let x = 3;
let mut x = 3;
println!("Number {}", x);
x = 5; // don't change this line
println!("Number {}", x);

View file

@ -1,9 +1,7 @@
// variables4.rs
// Make me compile! Execute the command `rustlings hint variables4` if you want a hint :)
// I AM NOT DONE
fn main() {
let x: i32;
let x: i32 = 10;
println!("Number {}", x);
}

View file

@ -1,11 +1,9 @@
// variables5.rs
// Make me compile! Execute the command `rustlings hint variables5` if you want a hint :)
// I AM NOT DONE
fn main() {
let number = "T-H-R-E-E";
println!("Spell a Number : {}", number);
number = 3;
let number = 3;
println!("Number plus two is : {}", number + 2);
}

View file

@ -1,9 +1,7 @@
// variables6.rs
// Make me compile! Execute the command `rustlings hint variables6` if you want a hint :)
// I AM NOT DONE
const NUMBER = 3;
const NUMBER: i8 = 3;
fn main() {
println!("Number {}", NUMBER);
}