30th Dec 2018, 10:12 PM
Hallg
Hallg - avatar
6 odpowiedzi
+ 3
There are 2 curly brackets at the end of if(18==age) one of them should be moved to after the last else statement
30th Dec 2018, 11:29 PM
CodeMStr
CodeMStr - avatar
+ 3
if (age >= 16){ if (age == 18){ Console.WriteLine("He is 18 years old"); } } ^ //wrong bracket else{ Console.WriteLine("He is 16 years old");} } 》//where it should be placed
30th Dec 2018, 11:30 PM
CodeMStr
CodeMStr - avatar
+ 3
This can be done more simply without nested if statements. Here is a demo: if(age>20) { Console.WriteLine("Adult"); } else if(age==18) { Console.WriteLine("He is 18 years old"); } else if(age==16) { Console.WriteLine("He is 16 years old"); } else { Console.WriteLine("He is a teenager"); }
31st Dec 2018, 2:43 PM
Seniru
Seniru - avatar
0
uu
2nd Jan 2019, 7:47 PM
Orhan Metin
Orhan Metin - avatar
0
It is better if you can drop in spaces between curly brackets and format the code.It will be helpful in debugging
3rd Jan 2019, 5:20 AM
Hari sankar
Hari sankar - avatar
- 2
Due to poor logic
31st Dec 2018, 6:36 PM
Hafiz usama