+ 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.

14th Jan 2017, 2:57 AM
Chaaru Manjuraj
Chaaru Manjuraj - avatar
5 Antworten
+ 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.
14th Jan 2017, 3:46 AM
Nahuel
Nahuel - avatar
+ 5
Show us the code, so we can check what is wrong.
14th Jan 2017, 3:02 AM
Nahuel
Nahuel - avatar
+ 3
No problem, happy coding :)!
14th Jan 2017, 3:48 AM
Nahuel
Nahuel - avatar
+ 1
Great... Thank you so much 😁
14th Jan 2017, 3:47 AM
Chaaru Manjuraj
Chaaru Manjuraj - avatar
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.*/
14th Jan 2017, 3:42 AM
Chaaru Manjuraj
Chaaru Manjuraj - avatar