C++ Online Compiler
Example: C++ Program to Find Grade of a Student using Nested If-else
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find Grade of a Student using Nested If-else #include <bits/stdc++.h> using namespace std; int main() { // To store the values of five subjects float sub_1, sub_2, sub_3, sub_4, sub_5; float total = 0.00, average = 0.00, percentage = 0.00; char grade; cout << "Enter the marks of five subjects::\n"; cin >> sub_1 >> sub_2 >> sub_3 >> sub_4 >> sub_5; // It will calculate the Total, Average and Percentage total = sub_1 + sub_2 + sub_3 + sub_4 + sub_5; average = total / 5.0; percentage = (total / 500.0) * 100; // It will calculate the Grade if (average >= 90) { grade = 'A'; } else { if (average >= 80 && average < 90) { grade = 'B'; } else { if (average >= 70 && average < 80) { grade = 'C'; } else { if (average >= 60 && average < 70) { grade = 'D'; } else { grade = 'E'; } } } } // It will produce the final output cout << "\nThe Total marks = " << total << "/500\n"; cout << "The Average marks = " << average << "\n"; cout << "The Percentage = " << percentage << "%\n"; cout << "The Grade = '" << grade << "'\n"; return 0; }
98 87 89 88 79
Output
Clear
ADVERTISEMENTS