0
0
C Sharp (C#)programming~10 mins

Else-if ladder execution in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if the number is positive.

C Sharp (C#)
int number = 10;
if (number [1] 0)
{
    Console.WriteLine("Positive number");
}
Drag options to blanks, or click blank then click option'
A>
B!=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' will check for negative numbers.
Using '==' checks only if number equals zero, not positive.
2fill in blank
medium

Complete the else-if condition to check if the number is zero.

C Sharp (C#)
int number = 0;
if (number > 0)
{
    Console.WriteLine("Positive number");
}
else if (number [1] 0)
{
    Console.WriteLine("Zero");
}
Drag options to blanks, or click blank then click option'
A!=
B>
C<
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' will check for any number except zero.
Using '<' or '>' will check for negative or positive numbers, not zero.
3fill in blank
hard

Fix the error in the else-if ladder to correctly check if the number is negative.

C Sharp (C#)
int number = -5;
if (number > 0)
{
    Console.WriteLine("Positive number");
}
else if (number == 0)
{
    Console.WriteLine("Zero");
}
else if (number [1] 0)
{
    Console.WriteLine("Negative number");
}
Drag options to blanks, or click blank then click option'
A>
B==
C<
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' will check for positive numbers, not negative.
Using '==' checks for equality, not less than.
4fill in blank
hard

Fill both blanks to complete the else-if ladder that prints the correct message based on the number.

C Sharp (C#)
int number = 0;
if (number [1] 0)
{
    Console.WriteLine("Positive number");
}
else if (number [2] 0)
{
    Console.WriteLine("Negative number");
}
Drag options to blanks, or click blank then click option'
A>
B<
C==
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' in these conditions will not separate positive and negative numbers.
Swapping the operators will cause wrong messages.
5fill in blank
hard

Fill all three blanks to complete the else-if ladder that prints the correct message for positive, zero, or negative numbers.

C Sharp (C#)
int number = 5;
if (number [1] 0)
{
    Console.WriteLine("Positive number");
}
else if (number [2] 0)
{
    Console.WriteLine("Zero");
}
else
{
    Console.WriteLine("[3] number");
}
Drag options to blanks, or click blank then click option'
A>
B==
CNegative
DZero
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong operators in conditions.
Printing wrong message in else block.