Group
Flow Control in C++
Objective
1. Prompt the user to enter a numeric grade (e.g., 0–100).
2. Use an if-else statement to evaluate whether the grade is 60 or higher.
3. Print "Passing" if the grade is 60 or above; otherwise, print "Failing".
4. Test the program with various inputs to verify the logic.
Write a program that asks for a grade and determines whether it is passing or failing.
Example C++ Exercise
Show C++ Code
#include <iostream> // Include the iostream library for input and output
using namespace std; // Use the standard namespace
// Main function - starting point of the program
int main() {
int grade; // Variable to store the grade input by the user
// Ask the user to enter a grade
cout << "Enter your grade (0-100): ";
cin >> grade; // Read the user's input
// Check if the grade is passing (60 or above)
if (grade >= 60) {
cout << "Passing" << endl; // Output if the grade is passing
} else {
cout << "Failing" << endl; // Output if the grade is failing
}
return 0; // Return 0 to indicate successful program execution
}
Output
Enter your grade (0-100): 75
Passing