Control flow is a fundamental concept in programming that allows you to dictate how your code executes based on certain conditions. In Rust, one of the ways to control the flow of your program is by using if-else
statements.
In this challenge, you will implement a function that checks whether a number is positive, negative, or zero. Depending on the value, your function should return a corresponding string message.
Your task is to complete the function check_number_sign
that takes an integer i32
as input and returns a String
indicating whether the number is "positive"
, "negative"
, or "zero"
.
"positive"
."negative"
."zero"
.if
, else if
, and else
keywords to implement the control flow.String
.mehdihmr
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. if number > 0{ return "positive".to_string(); } else if number < 0{ return "negative".to_string(); } else { return "zero".to_string(); }}
ethel-dev
pub fn check_number_sign(number: i32) -> String { if number > 0 { return "positive".to_string() } if number < 0 { return "negative".to_string() } return "zero".to_string()}
DivineGod
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. match number { n if n < 0 => "negative", n if n > 0 => "positive", _ => "zero", }.to_string() // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
Algorab
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. if number > 0 { "positive".to_string() } else if number == 0 { "zero".to_string() } else { "negative".to_string() }}
sroas
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
felipebalbi
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. match number.signum() { -1 => "negative".to_string(), 0 => "zero".to_string(), 1 => "positive".to_string(), _ => unreachable!(), }}
danielmpetrov
pub fn check_number_sign(number: i32) -> String { let res = if number > 0 { "positive" } else if number < 0 { "negative" } else { "zero" }; res.to_string()}
terminox
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. return String::from("zero");}
qiyuan711
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. let res = if number > 0{ "positive" } else if number <0 { "negative" } else { "zero" }; res.to_string()}
apst
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. if number > 0 { String::from("positive") } else if number < 0 { String::from("negative") } else { String::from("zero") }}
jw
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. if number > 0 { "positive".to_string() } else if number < 0 { "negative".to_string() } else { "zero".to_string() } // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
nickythorne
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
nickythorne
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
chuyuanlinzi
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { "positive".to_string() } // Step 2: // Check if the number is negative. else if number < 0 { "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. else { "zero".to_string() }}
DV-13
pub fn check_number_sign(number: i32) -> String { if number > 0i32 { String::from("positive") } else if number < 0i32 { String::from("negative") } else { String::from("zero") }}
DV-13
pub fn check_number_sign(number: i32) -> String { if number > 0i32 { return String::from("positive") } if number < 0i32 { return String::from("negative") } String::from("zero")}
yoakemae
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. else if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. else { return "zero".to_string(); }}
tinthid
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. String::from("zero")}
martin-unit
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 {"positive".to_string()} else if number < 0 {"negative".to_string()} else {"zero".to_string()} // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
Neil-Rayu
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. return String::from("zero");}
RonaldoArayadev
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. return "zero".to_string();}
3ok
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. return "zero".to_string()}
Thymelizabeth
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. String::from(match number.cmp(&0) { std::cmp::Ordering::Greater => "positive", std::cmp::Ordering::Equal => "zero", std::cmp::Ordering::Less => "negative", })}
dalprahcd
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. match number.cmp(&0) { std::cmp::Ordering::Greater => String::from("positive"), std::cmp::Ordering::Less => String::from("negative"), std::cmp::Ordering::Equal => String::from("zero"), }}
devarajang
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. return String::from("zero");}
jeypiti
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. if number > 0 { String::from("positive") } else if number < 0 { String::from("negative") } else { String::from("zero") }}
stdstring
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. return "zero".to_string();}
konishu
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. else if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. else { return "zero".to_string(); }}
nichideropa
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. if number > 0 { String::from("positive") } else if number < 0 { String::from("negative") } else { String::from("zero") }}
Cameo007
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. if number > 0 { String::from("positive") } else if number < 0 { String::from("negative") } else { String::from("zero") }}
aleksey-vareto
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
aleksey-vareto
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
akshayabhattarai
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0{ return "positive".to_string() } else if number < 0 { return "negative".to_string() } else { return "zero".to_string() }; // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
madeinheaven91
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. match number { 0 => "zero".to_string(), 1.. => "positive".to_string(), _ => "negative".to_string() } // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
oDqnger
pub fn check_number_sign(number: i32) -> String { if number > 0 { String::from("positive") } else if number < 0 { String::from("negative") } else { String::from("zero") }}
matsuby
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. return String::from("zero");}
ankeetparikh
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { "positive".to_string() } else if number < 0 { "negative".to_string() } else { "zero".to_string() }}
ankeetparikh
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string(); } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string(); } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
0xsmarter
pub fn check_number_sign(number: i32) -> String { if number > 0 { "positive".to_string() } else if number < 0 { "negative".to_string() } else { "zero".to_string() }}
aidan1magee
pub fn check_number_sign(number: i32) -> String { if number > 0 { "positive".to_string() } else if number < 0 { "negative".to_string() } else { "zero".to_string() }}
maxvi
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } // Step 2: // Check if the number is negative. if number < 0 { return "negative".to_string() } // Step 3: // Handle the case where it's neither positive nor negative. "zero".to_string()}
koslowskio
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number>0 { return "positive".to_string() } else if number<0 { return "negative".to_string() } else { return "zero".to_string() }}
P0TER19
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. let message : &str = if number > 0 { "positive" } // Step 2: // Check if the number is negative. else if number < 0 { "negative" } // Step 3: // Handle the case where it's neither positive nor negative. else { "zero" }; return String::from(message)}
P0TER19
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. let message : &str = if number > 0 { "positive" } // Step 2: // Check if the number is negative. else if number < 0 { "negative" } // Step 3: // Handle the case where it's neither positive nor negative. else { "zero" }; return String::from(message)}
rafaellucasprogm
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return "positive".to_string() } else if number < 0 { return "negative".to_string() } else { return "zero".to_string() }}
WalquerX
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative. if number > 0 { return "positive".to_string() } else if number < 0 { return "negative".to_string() } else { return "zero".to_string() }}
cloki0610
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number > 0 { return String::from("positive"); } // Step 2: // Check if the number is negative. if number < 0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. String::from("zero")}
Brack0
pub fn check_number_sign(number: i32) -> String { if number.is_positive() { return "positive".to_string(); } if number.is_negative() { return "negative".to_string(); } "zero".to_string()}
shinuza
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. match number { x if x > 0 => "positive".to_string(), x if x < 0 => "negative".to_string(), _ => "zero".to_string() } // Step 2: // Check if the number is negative. // Step 3: // Handle the case where it's neither positive nor negative.}
CountJung
pub fn check_number_sign(number: i32) -> String { // Return `"positive"` if the number is positive. // Return `"negative"` if the number is negative. // Return `"zero"` if the number is zero. // Step 1: // Check if the number is positive. if number>0 { return String::from("positive"); } // Step 2: // Check if the number is negative. else if number<0 { return String::from("negative"); } // Step 3: // Handle the case where it's neither positive nor negative. else if number==0 { return String::from("zero"); } else { //"Nothing" String::from("Reach here will be Panic!!!!!!") } }