B.Tech Students: Apply for Live Programming Internship C, C++, Java, Python ,Web page Designing, PHP C++ If-Else Statements | Login Technologies

C++ If-Else Statements

C++ if-else statements allow you to perform different actions based on conditions.

C++ में if-else स्टेटमेंट्स का उपयोग कंडीशन के अनुसार अलग-अलग कार्य करने के लिए किया जाता है।

Example: Basic if-else
#include <iostream>
using namespace std;

int main() {
  int number;
  cout << "Enter a number: ";
  cin >> number;

  if (number % 2 == 0) {
    cout << "Even number" << endl;
  } else {
    cout << "Odd number" << endl;
  }

  return 0;
}

Output: (User enters 5)

Odd number

The program checks whether a number is even or odd.

यह प्रोग्राम जाँचता है कि संख्या even है या odd।

Example: Nested if-else
#include <iostream>
using namespace std;

int main() {
  int age;
  cout << "Enter your age: ";
  cin >> age;

  if (age >= 18) {
    if (age >= 60) {
      cout << "Senior Citizen" << endl;
    } else {
      cout << "Adult" << endl;
    }
  } else {
    cout << "Minor" << endl;
  }

  return 0;
}

Output: (User enters 65)

Senior Citizen

This nested if-else checks multiple conditions.

यह nested if-else कई conditions को जाँचता है।