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

Why conditional flow control is needed in C Sharp (C#) - Test Your Understanding

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

Complete the code to check if a 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.
2fill in blank
medium

Complete the code to print "Even" if the number is divisible by 2.

C Sharp (C#)
if (number % 2 [1] 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 '!=' will check for odd numbers instead.
3fill in blank
hard

Fix the error in the conditional to 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 '>' excludes exactly 18, which is incorrect here.
4fill in blank
hard

Fill both blanks to check if a number is between 10 and 20 (inclusive).

C Sharp (C#)
if (number [1] 10 && number [2] 20) {
    Console.WriteLine("Between 10 and 20");
}
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '<=' excludes 20, which is incorrect.
5fill in blank
hard

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

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