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); }
7 ответов
+ 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 (;)
+ 1
Thanks a lot :)
+ 1
Razvan Tivadar Glad to help a buddy out
+ 1
Bro, Very Simple mistake you do.
You remove semicolon then run it, Buddy.
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);
}
0
Oh, ok, but if i wanted to change the if statement to (x+y<10) shouldn't the else statement work?
0
Razvan Tivadar Yes since x+y = 15
and 15 < 10 is false, the else statement should execute in this case.