C
C#8mo ago
koray bey

Confused about if statements

int sumPos = 0;
int sumNeg = 0;
bool isEmpty = false;
if (input is [])
{
Console.WriteLine("[] you entered an empty array");
isEmpty = true;
}
else //the line I talk about when I add else if(isEmpty = false)
{
Debug.WriteLine("isEmpty = false");
foreach (int i in input)
{
if (i > 0)
{
sumPos += i;
}
else if (i < 0)
{
sumNeg += i;
}
}
Console.WriteLine("Sum of the positives: " + sumPos + "\nSum of the negatives: " + sumNeg);
}

int sumPos = 0;
int sumNeg = 0;
bool isEmpty = false;
if (input is [])
{
Console.WriteLine("[] you entered an empty array");
isEmpty = true;
}
else //the line I talk about when I add else if(isEmpty = false)
{
Debug.WriteLine("isEmpty = false");
foreach (int i in input)
{
if (i > 0)
{
sumPos += i;
}
else if (i < 0)
{
sumNeg += i;
}
}
Console.WriteLine("Sum of the positives: " + sumPos + "\nSum of the negatives: " + sumNeg);
}

when I add else if instead of else the condition is met even in the debugging but it skips the else if statement
1 Reply
koray bey
koray beyOP8mo ago
fixed seems like bools also need double equal signs
Want results from more Discord servers?
Add your server