0

Multiple condition in cs

Is there a way to add multiple condition to an answer E.g : if (condition 1 and condition 2) {Execute this statement;} Or maybe there's a way to add range E.g : if (x is >2 & < 6 ) [i.e 3,4 or 5. Is true] {Execute this statement;} Please if you have any idea on how to implement the this in C# comment below

4th Nov 2021, 12:06 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar
10 odpowiedzi
+ 6
Have you gotten to this part of the tutorial yet? https://www.sololearn.com/learn/CSharp/2598/?ref=app
4th Nov 2021, 12:15 PM
Ipang
+ 3
Share a link to your code bit so we can sort it out ... https://www.sololearn.com/post/75089/?ref=app
4th Nov 2021, 12:21 PM
Ipang
+ 3
Ipang it's alright now thanks 🙏🙏🙏
4th Nov 2021, 12:36 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar
+ 2
U can use nested if instead of writing More condition in one if statement
4th Nov 2021, 12:16 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 2
So I think I've got it my mistake was using (x > 2 && < 6) instead of (x > 2 && x < 6) . Here's my code feel free to like https://code.sololearn.com/c9QXsPnPimfE/?ref=app
4th Nov 2021, 12:30 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar
+ 2
int x = Convert.ToInt32(Console.ReadLine()); string a = (x < 0) ? "unborn" : (x <= 4) ? "toddler" : (x <= 13) ? "child" : (x <= 17) ? "teenager" : (x < 49) ? "adult" : (x < 70) ? "elderly" : (x <= 90) ? "aged" : "You're really old, But how the hell are you still alive ;-)" ; Console.WriteLine(a); // Keep learning & happy coding :D
4th Nov 2021, 1:58 PM
SoloProg
SoloProg - avatar
+ 1
You mean something like this in the if declaration? If (x >= 2 && x < 6) { // code goes here } Or more conditions?
4th Nov 2021, 12:15 PM
Tim
Tim - avatar
+ 1
Ipang yes but it's not working in my code I'll recheck to be sure
4th Nov 2021, 12:19 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar
+ 1
Muhammad too many ifs nearly made me mad. 😁 but it's fixed now
4th Nov 2021, 12:34 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar
0
Terel yes
4th Nov 2021, 12:19 PM
Morakinyo Akinloluwa
Morakinyo Akinloluwa - avatar