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

If statement execution flow 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#)
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 code to print "Even" when the number is divisible by 2.

C Sharp (C#)
if (number [1] 2 == 0) {
    Console.WriteLine("Even");
}
Drag options to blanks, or click blank then click option'
A%
B+
C-
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' or '-' instead of '%' will not check divisibility.
Using '*' will multiply, not check remainder.
3fill in blank
hard

Fix the error in the if statement to correctly check if age is at least 18.

C Sharp (C#)
if (age [1] 18) {
    Console.WriteLine("Adult");
}
Drag options to blanks, or click blank then click option'
A<=
B==
C<
D>=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' checks if age is less than or equal to 18, which is incorrect here.
Using '==' checks only if age equals 18, not greater.
4fill in blank
hard

Fill both blanks to print "Teenager" if age is between 13 and 19 inclusive.

C Sharp (C#)
if (age [1] 13 && age [2] 19) {
    Console.WriteLine("Teenager");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' excludes 19 from the range.
Using '>' instead of '>=' excludes 13 from the range.
5fill in blank
hard

Fill the blanks to print "Grade A" if score is above 90, "Grade B" if score is above 80, else "Grade C".

C Sharp (C#)
if (score [1] 90) {
    Console.WriteLine("Grade A");
} else if (score [2] 80) {
    Console.WriteLine("Grade B");
} else {
    Console.WriteLine("Grade C");
}
Drag options to blanks, or click blank then click option'
A>=
B>
C<=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' includes 90 in Grade A, but the question says 'above 90'.
Using '<=' in the else if condition is incorrect here.