Grade Classification in CSharp
Table of Contents
- Grade Classification in CSharp
- Introduction of the Lesson
- Objectives
- Beginner-Friendly Source Code and Step-by-Step Instructions
- Step-by-Step Instructions
- Program.cs
- Example Output
- Explanation of the Program
- Summary
- 5-Item Multiple Choice Quiz (Bloom’s Taxonomy)
- Exercises, Assessment, and Lab Exam
- Introductory Note
- Exercises
- Assessment Task
- Lab Exam
Introduction of the Lesson
In programming, decision-making is one of the most powerful concepts. It allows a program to react differently based on given conditions—just like how teachers classify student grades. In this lesson, you will learn how to use conditional statements in C# (such as if, if-else, and else-if) to classify grades based on numeric input. By applying these logical structures, you can create interactive programs that evaluate scores and produce meaningful results.
Conditional statements are essential for controlling the flow of execution in a program. For example, when a student’s score is above 90, the program can output an “A”, while lower scores result in other grades. Understanding how to use if-else conditions helps you build smart, flexible, and real-world programs.
Objectives
This lesson focuses on developing your logical thinking and programming problem-solving skills. You’ll not only learn how conditions work in C#, but also practice applying them to real-life scenarios.
After completing this lesson, you should be able to:
- Understand: Explain how conditional statements (if, if-else, else-if) control program logic in C#.
- Learn: Identify the syntax and purpose of conditional statements to classify grades.
- Practice: Write and test a C# program that reads a numeric score and outputs the corresponding grade.
- Apply: Modify the grade classification program to include validation and handle more complex grading systems.
Beginner-Friendly Source Code and Step-by-Step Instructions
Step-by-Step Instructions
- Open Visual Studio Code and ensure you have the .NET SDK installed.
- Create a new console project in your working folder:
dotnet new console -n grade_classification - Navigate into the project folder:
cd grade_classification - Open
Program.csand replace the contents with the code below. - Save your file and run the program using:
dotnet run
Program.cs
using System;
namespace GradeClassificationApp
{
class Program
{
static void Main(string[] args)
{
Console.Write("Enter your grade (0-100): ");
double grade = Convert.ToDouble(Console.ReadLine());
if (grade >= 90)
{
Console.WriteLine("Your grade is A");
}
else if (grade >= 80)
{
Console.WriteLine("Your grade is B");
}
else if (grade >= 70)
{
Console.WriteLine("Your grade is C");
}
else if (grade >= 60)
{
Console.WriteLine("Your grade is D");
}
else
{
Console.WriteLine("Your grade is F");
}
}
}
}
Example Output
Enter your grade (0-100): 85
Your grade is B
Another example:
Enter your grade (0-100): 59
Your grade is F
Explanation of the Program
This program demonstrates how to use if-else-if statements to classify grades based on a numeric value.
- The program begins by prompting the user to enter their grade (a number between 0 and 100).
- It then uses if statements to check whether the grade meets certain conditions.
- If the grade is 90 or higher, the student receives an A.
- If it’s 80–89, the grade is B, and so on.
- Only one block executes because the conditions are mutually exclusive.
- Finally, the appropriate grade is displayed using
Console.WriteLine().
This type of program models real-world evaluation systems where decisions depend on specific numeric thresholds.
Summary
In this lesson, you learned how to use if-else conditional statements in C# to classify grades. Conditional statements help your program make decisions by checking if a certain condition is true or false. By mastering this concept, you can create smarter and more interactive applications. You also discovered how to compare numeric values and display results accordingly. This foundational knowledge prepares you for more complex programs, such as grading systems, eligibility checkers, and menu-driven applications.
5-Item Multiple Choice Quiz (Bloom’s Taxonomy)
- What C# statement is used to perform decision-making?
A. switch
B. if
C. loop
D. for - What will the program display if the input grade is 72?
A. A
B. B
C. C
D. D - Which of the following is the correct syntax for an if-else statement?
A. if (x > y) then { … }
B. if x > y { … }
C. if (x > y) { … } else { … }
D. if x > y: { … } - Why is only one condition executed in the example?
A. Because all conditions run in parallel
B. Because only one condition can be true
C. Because of a loop
D. Because of a function - Which logical structure is best for mutually exclusive grading conditions?
A. while loop
B. nested loop
C. if-else chain
D. switch without default
Exercises, Assessment, and Lab Exam
Introductory Note
To master the concept of conditional statements, you must practice writing, testing, and modifying your code. These exercises help strengthen your understanding of how decisions shape program flow and output.
Exercises
- Modify the program to include “Invalid input” if the user enters a number greater than 100 or less than 0.
- Change the grading system to include a “+” for high scores (e.g., 95+ = A+).
- Display a message like “Excellent!”, “Good job!”, or “Needs improvement” depending on the grade.
- Allow the user to enter multiple grades and display their classifications one by one.
- Convert the numeric grades into descriptive remarks (e.g., 90–100 = Outstanding).
Assessment Task
- Written Task: Explain in your own words how if-else statements help in programming decision-making.
- Performance Task: Write a program that accepts a grade and outputs both its letter classification and remark.
Lab Exam
Task:
Write a C# program that accepts a student’s grade and displays:
- The letter grade (A, B, C, D, F)
- A corresponding remark:
- A = Excellent
- B = Good
- C = Fair
- D = Needs Improvement
- F = Failed
Use if-else statements only. The output must be clear and formatted neatly.
You may visit our Facebook page for more information, inquiries, and comments. Please subscribe also to our YouTube Channel to receive free capstone projects resources and computer programming tutorials.
Hire our team to do the project.