Bird
0
0

You have a variable char grade that can be 'A', 'B', 'C', 'D', or 'F'. You want to print a message for each grade. Which is the most efficient way?

hard📝 Application Q9 of 15
C - onditional Statements
You have a variable char grade that can be 'A', 'B', 'C', 'D', or 'F'. You want to print a message for each grade. Which is the most efficient way?
AUse if statements with floating-point comparisons
BUse if-else statements comparing grade with strings
CUse switch with integer ranges for grades
DUse a switch statement with cases for each grade character
Step-by-Step Solution
Solution:
  1. Step 1: Understand the variable type and values

    grade is a char with discrete values 'A' to 'F'.
  2. Step 2: Choose the best control structure

    Switch works well with char constants; if-else with strings is incorrect; ranges and floats are not applicable.
  3. Final Answer:

    Use a switch statement with cases for each grade character -> Option D
  4. Quick Check:

    Switch with char cases = A [OK]
Quick Trick: Switch works well with char values like grades [OK]
Common Mistakes:
  • Comparing chars with strings
  • Using ranges in switch
  • Using floats in conditions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes