+ 1

What's wrong with this code ?

Edit : Why does this code loop the true. https://code.sololearn.com/cf6WrHQR8L01/?ref=app

27th Apr 2020, 5:28 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
5 Answers
+ 3
Main is void function, you write return statement in main for what purpose.. It's an error.. If you mean for output, write like this.. if (char.IsNumber(e) || convert[e] <= 1 || convert[e] >= 0) { Console.WriteLine(true); } else { Console.WriteLine(false); }
27th Apr 2020, 5:35 PM
Jayakrishna 🇼🇳
+ 1
It worked jayakrishna, thanks. But the foreach loop loops the true output with number of characters. How do I solve that ?.
27th Apr 2020, 5:52 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
+ 1
What you are trying..? What is your required output..? Edit: Also convert [e] is not works.. Because there e is charecter either '0' or '1'. convert[e] means convert[48] or convert[49], indexoutofbounds exception.. Write just e=='1' , e=='0'
27th Apr 2020, 5:54 PM
Jayakrishna 🇼🇳
+ 1
Jayakrishna, thanks again.
27th Apr 2020, 8:43 PM
Joseph Oritseweyinmi
Joseph Oritseweyinmi - avatar
0
Its true because char.isNumber(e) is always true.. For a single true or false.. Like this: static void Main(string[] args) { string input = "101101"; char[] convert = input.ToCharArray(); bool b=true; foreach (var e in convert) { if(char.IsNumber(e) && (e == '1' || e == '0')) { continue; } else { b=false; break; } } Console.WriteLine(b); } And Joseph Oritseweyinmi you're welcome ...
28th Apr 2020, 10:29 AM
Jayakrishna 🇼🇳