C++ Online Compiler
Example: C++ Program to Find Grade of a Student using Function
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find Grade of a Student using Function #include <bits/stdc++.h> using namespace std; // This function will display the percentage, average, and grade void CalcPercentGrade(float sub_1, float sub_2, float sub_3, float sub_4, float sub_5) { float total = 0.00, average = 0.00, percentage = 0.00; char grade; // 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"; } // It's the driver function int main() { // To store the values of five subjects float sub_1, sub_2, sub_3, sub_4, sub_5; cout << "Enter the marks of five subjects::\n"; cin >> sub_1 >> sub_2 >> sub_3 >> sub_4 >> sub_5; // It will produce the final output CalcPercentGrade(sub_1, sub_2, sub_3, sub_4, sub_5); return 0; }
98 87 89 88 79
Output
Clear
ADVERTISEMENTS