c++ multiple if conditions

#include <iostream>
using namespace std;

int main() {
    int x = 10;

    if (x == 5) {
        cout << "x is equal to 5" << endl;
    } else if (x == 10) {
        cout << "x is equal to 10" << endl;
    } else {
        cout << "x is neither 5 nor 10" << endl;
    }

    return 0;
}

Explanation:

  • The program starts by including the necessary header file iostream for input and output operations.
  • using namespace std; allows us to use elements from the std namespace without prepending std::.
  • int main() is the entry point of the program.
  • int x = 10; declares an integer variable x and initializes it with the value 10.
  • The if-else if-else construct checks the value of x:
  • if (x == 5) checks if x is equal to 5.
    • If true, it prints "x is equal to 5".
  • else if (x == 10) checks if x is equal to 10.
    • If true, it prints "x is equal to 10".
  • If none of the conditions above are true, the else block executes and prints "x is neither 5 nor 10".
  • return 0; signifies successful completion of the main() function with a return status of 0.