C++ also has various decision-making constructs which aid the programmer in decision making.
It involves using conditional statements to execute certain blocks of code based on certain conditions.

Decision making can occur these forms:
  • if statement
  • if - else statement
  • if - else if statement
  • nested if statements
  • switch statement

Example:

Below is a code to check if a number is positive or negative.

#include <iostream>
using namespace std;
int main()
{
    int num;
    cout << " Enter the number: ";
    cin >> num;
    if ( num == 0 ) 
    
           cout << " The number entered is 0 " << endl;
     }
    else if(num < 0)
    {
           cout << " The number is negative " << endl;
    }
    else
    {
           cout << " The number is positive " << endl;
    }
 
    return 0;

}


Switch Statement:

The switch statement evaluates a conditional expression and then matches the value of this expression to each case. When the expression value matches the case, the statement code of this case is executed.

Example:

Below is a code to check if the entered character is a uppercase vowel or not.

#include <iostream>
using namespace std;
int main()
{
     char mychar;
     cout << " Enter an uppercase vowel character: " ; 
     cin >> mychar;

     switch ( mychar )
     {
 
      case 'A':  
     {
         cout<<"Character entered is A"<<endl;
         break;
      }
      case 'E':  
     {
         cout <<  " Character entered is E " << endl;
         break;
     }
      case 'I':   
     {
         cout << " Character entered is I " << endl;
         break;
     }
      case 'O':  
     {
         cout << " Character entered is O " << endl;
         break;
     }
      case 'U':  
     {
         cout << " Character entered is U " << endl;
         break;
     }
      default: 
     {
         cout << " Vowel was not entered " << endl;
     }
     }
     return 0;
}