
If you’re new to C++ programming and want to learn how to use conditional statements effectively, this post will walk you through a simple but practical example — a program that calculates a student’s grade based on their marks.
🧠 What You’ll Learn
- How to take input from the user in C++
- How to use
if
,else if
, andelse
statements - How to apply logical operators (
&&
) for range checking - How to output results clearly using
cout
💻 C++ Program Code
Below is the complete code from your uploaded file:
/* C++ Program to Find Grade of a Student using if else */
#include<iostream>
using namespace std;
int main()
{
int a;
cout << "Enter Student's Marks:: \n";
cin >> a;
if (a > 90 && a <= 100)
{
cout << "Grade A+\n";
}
else if (a > 80 && a <= 90)
{
cout << "Grade A\n";
}
else if (a > 70 && a <= 80)
{
cout << "Grade B\n";
}
else if (a > 60 && a <= 70)
{
cout << "Grade C\n";
}
else if (a > 50 && a <= 60)
{
cout << "Grade C\n";
}
else
{
cout << "Grade D\n";
}
return 0;
}
🧩 How the Program Works
- The program first prompts the user to enter a student’s marks.
- Using if-else conditions, it checks which range the marks fall into.
- Depending on the marks, it prints out the corresponding grade.
For example:- 91–100 → Grade A+
- 81–90 → Grade A
- 71–80 → Grade B
- 61–70 → Grade C
- 51–60 → Grade C
- Below 50 → Grade D
⚙️ Output Example
Input:
Enter Student's Marks::
85
Output:
Grade A
✅ Key Takeaways
- The program demonstrates basic conditional logic in C++.
- It’s a great starting point for learning decision-making structures.
- You can expand it further by:
- Adding validation for invalid marks (e.g., negative or above 100).
- Using
switch
statements or functions for cleaner design. - Displaying remarks like Excellent, Good, or Needs Improvement.
🏁 Conclusion
The Student Grade Program in C++ is a perfect beginner exercise to understand how conditional statements work. It helps you practice input/output, logical operators, and decision control — all essential for building more advanced programs later on.