+ 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.".
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.....
......
+ 2
that is because, you used Console.ReadLine() for a char
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 ; )
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
0
Then what should we used instead of console. ReadLine() for such type of statement.
0
You should use:
char a = Convert.ToChar(Console.ReadLine);
--
or, the easiest way:
char a = Console.ReadLine[0];
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
0
bool x;
Convert.ToInt(x); //x is now an int
Convert.ToString(x); //x is now a String
...