0

Why doesn't my code work?

static void Main(string[] args) { double x = 5; double y = 10; if (x + y > 10) ; { string bho = "I did it!"; Console.WriteLine("What's up?"); Console.ReadLine(); Console.WriteLine("{0}, it wasn't that hard actually", bho); } else { string gdm = "Goddamnit!"; Console.WriteLine("Whats'up?"); Console.ReadLine(); Console.WriteLine("{0},I screwed up!", gdm); }

3rd Mar 2020, 11:28 AM
Razvan Tivadar
Razvan Tivadar - avatar
7 RĂ©ponses
+ 2
Remove the semicolon (;) on the if statement. Your code should work well after removing it. The if statement should be followed by brackets { } not by semicolons (;)
3rd Mar 2020, 11:34 AM
かんでん
かんでん - avatar
+ 1
Thanks a lot :)
3rd Mar 2020, 11:46 AM
Razvan Tivadar
Razvan Tivadar - avatar
+ 1
Razvan Tivadar Glad to help a buddy out
3rd Mar 2020, 11:47 AM
かんでん
かんでん - avatar
+ 1
Bro, Very Simple mistake you do. You remove semicolon then run it, Buddy.
3rd Mar 2020, 1:54 PM
ÆŹIMΛ
ÆŹIMΛ - avatar
0
This should work well static void Main(string[] args) { double x = 5; double y = 10; if (x + y > 10) { string bho = "I did it!"; Console.WriteLine("What's up?"); Console.ReadLine(); Console.WriteLine("{0}, it wasn't that hard actually", bho); } else { string gdm = "Goddamnit!"; Console.WriteLine("Whats'up?"); Console.ReadLine(); Console.WriteLine("{0},I screwed up!", gdm); }
3rd Mar 2020, 11:35 AM
かんでん
かんでん - avatar
0
Oh, ok, but if i wanted to change the if statement to (x+y<10) shouldn't the else statement work?
3rd Mar 2020, 11:37 AM
Razvan Tivadar
Razvan Tivadar - avatar
0
Razvan Tivadar Yes since x+y = 15 and 15 < 10 is false, the else statement should execute in this case.
3rd Mar 2020, 11:39 AM
かんでん
かんでん - avatar