+ 3

How to add multiple OR(||) and AND(&&) operator in if... Else statement?

When I try to add it gives error like.... " cannot used || operator for bool or char.".

17th Jun 2016, 6:37 PM
Ajay Mangaj
8 odpowiedzi
+ 2
for example: int a = 7; if (a>98 || a==5 || a==54) { Console.Write(a); } else ..... or if (a>2 && a<5 && a=!3) { Console.Write("a should be 4") } else..... ......
17th Jun 2016, 6:46 PM
Mitiko
Mitiko - avatar
+ 2
that is because, you used Console.ReadLine() for a char
17th Jun 2016, 7:04 PM
erwinmesi
erwinmesi - avatar
0
Can you give more info for your code? I'll probably be able to find your mistake. Else Try searching your error in google. Compiler error 1002 c# (that is when you forgot the ; )
17th Jun 2016, 6:52 PM
Mitiko
Mitiko - avatar
0
Example: Console.WriteLine("value of a="); Char a= Console.ReadLine(); if(b>2 && c>3 || c>2) ...... Else ...... It gives error like... "cannot implicitly convert type 'string' to 'char'..." So now please tell me how to convert it... And how to use in code
17th Jun 2016, 7:03 PM
Ajay Mangaj
0
Then what should we used instead of console. ReadLine() for such type of statement.
17th Jun 2016, 7:09 PM
Ajay Mangaj
0
You should use: char a = Convert.ToChar(Console.ReadLine); -- or, the easiest way: char a = Console.ReadLine[0];
19th Jun 2016, 2:19 PM
erwinmesi
erwinmesi - avatar
0
also, be careful with those conditions. mind you, a&&b||c is very different from a&&(b||c), always write down the behavior you expect and then write the code for it
20th Jun 2016, 7:05 AM
Matheus Fernandes
Matheus Fernandes - avatar
0
bool x; Convert.ToInt(x); //x is now an int Convert.ToString(x); //x is now a String ...
22nd Jun 2016, 12:07 PM
I.A.Sebsil83
I.A.Sebsil83 - avatar