Wednesday, May 20, 2020

Else statement in C++

  • Syntax :


      if (condition
         {
         // block of code to be executed if the condition is true
         } 
        else 
         {
        // block of code to be executed if the condition is false
         }

  • Program :
#include <iostream>
using namespace std;

int main() {
  cout <<"\n----------------ELSE STATEMENT----------------\n";
  int a;
  cout<<"\nEnter your age :";
  cin>>a;
  if (a >= 18) {
    cout <<"\nMajor";
  }
  else  {
    cout <<"\nMinor";
  }
  return 0;
}


  • Output :

No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...