Computer scienceProgramming languagesC++Operators and expressions

Logical operators

Conditions

Report a typo

What will be the output of the following code snippet?

#include <iostream>
using namespace std;

int main() {
    int mathScore = 8, physicsScore = 12, passingScore = 5;

    bool hasGoodMathScore = (mathScore > physicsScore) && (physicsScore > passingScore);
    bool hasPassedOneSubject = (mathScore % passingScore == 0) || (physicsScore % passingScore == 0);
    
    if (hasGoodMathScore && hasPassedOneSubject) {
        cout << "You're excelling in both subjects and have passed at least one!" << endl;
    } else {
        cout << "You either need to improve or should focus on passing at least one subject." << endl;
    }
    
    return 0;
}
Select one option from the list

Create a free account to access the full topic