C++ Conditions - Software Engineering

In this chapter, We will learn C++ Conditions and its types and its usage with examples, C++ Conditions – Software Engineering has a big part of C++

C++ Conditions and If Statements

In C++, we are usually, use these type of conditions:

  • Less than: x < y
  • Less than or equal to: x <= y
  • Greater than: x > y
  • Greater than or equal to: x >= y
  • Equal to: x == y
  • Not Equal to: x != y

So, you can use these conditions to perform different actions for different decision making. C++ has the following conditional statements:

  • if is a conditional operator is determining a block of code has executed, if a specified condition is valid/true
  • the Use else is determining a block of code has executed if a similar condition is false
  • Uses else if is determining a condition is testing if the first condition is false.
  • Use of switch is specifying many alternative blocks of code has executed

So, the C++ Conditions, Software Engineering. I am explaining an example below, which will contain the use if and telling you how to make building blocks.

The ‘If’ the statement is:

the usage of if the statement is specifying a block C++ code will execute if a condition is true/valid.

So, the Syntax is:

#include <iostream>
using namespace std;

int main()
{
   if(condition)
   {
        // block C++ code will execute if a condition is true/valid.
   }
   return 0;
}

Note: In C++, You can only use lower case if. don’t use of upper case IF or regular case If, it will generate an error.

C++ Conditions – Software Engineering

Most of Software Engineering is done by C++. So, In the next chapters, I will teach c++ professionally how to use in software engineering.

There are two examples that I teach you how you can use ‘if‘ statements to comparison integer values.

So, see Example 1:

#include <iostream>
using namespace std;

int main()
{
     if(40 > 15)
     {
        cout << "40 is Greater than 15";     
     }
     return 0;
}

In the above example, we explained to you, how can you make a comparison between two values, So Now the anther example which you can make a comparison between two variables. Example:

#include <iostream>
using namespace std;

int main()
{
     int x = 40;
     int y = 15;
     if(x > y)
     {
        cout << "x is Greater than y";     
     }
     return 0;
}

🔥 Hope you are crazy to learn, So give your feedback in the comment section… Follow us on FB TCMaster

By Usama Arshad

It's me Usama Arshad working as a Lecturer C++. I am a student of BSIT.

Leave a Reply

Your email address will not be published. Required fields are marked *