if else Statement in C++ Programming


The if else statement executes a block of code if a specified condition is true. If the condition is false, another block of code can be executed. An if statement executes code conditionally depending on the result of the condition in parentheses.

When condition in parentheses is true it will enter to the block of if statement which is defined by curly braces like open braces and close braces. Opening bracket till the closing bracket is the scope of the if statement. The else block is optional and can be omitted. It runs if the if statement is false and does not run if the if statement is true because in that case if statement executes.

 Syntax :
   if ( condition )
   {
       // block of statement to be executed if condition is true ;
   }
   else
   {
       block of statement to be executed if condition is false ;
   }

The program is written in C++ language and it checks whether a given character is a vowel or not. Here's how the program works:

  • It first declares a character variable 'c' to store the input character.
  • The user is then prompted to enter a character, which is read by the 'cin' statement.
  • The program checks if the character entered by the user is any of the vowels 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', or 'U' by using a logical OR operator ('||') to combine multiple conditions.
  • If the entered character is a vowel, the program displays a message saying that the character is a vowel.
  • If the entered character is not a vowel, the program displays a message saying that the character is not a vowel.
  • Finally, the program returns 0, indicating successful execution.

Source Code

#include<iostream>
using namespace std;
 
//aeiou AEIOU
int main()
{
    char c;
    cout<<"Enter The Character : ";
    cin>>c;
    if(c=='a' || c=='e' ||c=='i' ||c=='o' ||c=='u' || c=='A' || c=='E' ||c=='I' ||c=='O' ||c=='U')
    {
        cout<<c<<" is a Vowel";
    }
    else
    {
       cout<<c<<" is not a Vowel";
    }
    return 0;
}
 

Output

Enter The Character : s
s is not a Vowel
To download raw file Click Here

Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples