From e47d4c4c068904c58da7e28fe69c0beb0442dee2 Mon Sep 17 00:00:00 2001 From: Raghu Ganapathy Date: Sat, 15 Jul 2023 22:16:26 -0700 Subject: [PATCH] fix: worked till if and quiz 1 --- exercises/if/if1.rs | 11 +++++------ exercises/if/if2.rs | 9 ++++++--- exercises/quiz1.rs | 14 +++++++++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/exercises/if/if1.rs b/exercises/if/if1.rs index 587e03f8..0910a05e 100644 --- a/exercises/if/if1.rs +++ b/exercises/if/if1.rs @@ -1,13 +1,12 @@ // if1.rs // Execute `rustlings hint if1` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn bigger(a: i32, b: i32) -> i32 { - // Complete this function to return the bigger number! - // Do not use: - // - another function call - // - additional variables + if(a>b){ + return a; + }else{ + return b; + } } // Don't mind this for now :) diff --git a/exercises/if/if2.rs b/exercises/if/if2.rs index effddbb6..69018855 100644 --- a/exercises/if/if2.rs +++ b/exercises/if/if2.rs @@ -4,14 +4,17 @@ // Step 2: Get the bar_for_fuzz and default_to_baz tests passing! // Execute `rustlings hint if2` or use the `hint` watch subcommand for a hint. -// I AM NOT DONE - pub fn foo_if_fizz(fizzish: &str) -> &str { if fizzish == "fizz" { "foo" } else { - 1 + if fizzish =="fuzz"{ + "bar" + }else{ + "baz" + } } + } // No test changes needed! diff --git a/exercises/quiz1.rs b/exercises/quiz1.rs index dbb5cdc9..bcb19561 100644 --- a/exercises/quiz1.rs +++ b/exercises/quiz1.rs @@ -10,10 +10,18 @@ // Write a function that calculates the price of an order of apples given // the quantity bought. No hints this time! -// I AM NOT DONE - // Put your function here! -// fn calculate_price_of_apples { +fn calculate_price_of_apples(no_of_apples:i32)->i32{ + let mut price_of_apples :i32; + if no_of_apples >40{ + price_of_apples = no_of_apples; + }else{ + price_of_apples = 2*no_of_apples; + } + + println!("Price of {} is {}",no_of_apples, price_of_apples); + return price_of_apples; +} // Don't modify this function! #[test]