+ 1
I typed the statement x<y, the code is running without errors. Output is showing x is greater than y.
If the code runs as well after giving the condition opposite to the integers, then what is the use of if statements? Anyone please help me.
5 odpowiedzi
+ 6
Your problem is that you have a semicolon ; after the if.
if (x < y);
That is the error, you just need to write like this:
if(x<y){code}
you are just ending the if statemment the other way.
Also, > is greater, < is lesser.
+ 5
Show us the code, so we can check what is wrong.
+ 3
No problem, happy coding :)!
+ 1
Great... Thank you so much 😁
0
static void Main(string[] args)
{
int x;
x = 9;
int y;
y = 5;
if (x < y);
{
Console.WriteLine("x is greater than y");
Console.ReadLine();
}
}
/* If I code like this, (opposite statement with respect to typed integers) the code shouldn't run. But it executes and shows the output 'x is greater than y'. Please tell me what's wrong with this code.*/