c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
C++

How to use if else statement in c++?

| | c
#include <iostream>

using namespace std;

int main()
{
  int a,b;
  cout<<"enter the a and b values:";
  cin>>a>>b;
  if(a>b)
  {
      cout<<"a is biggest";
  }
  else
  {
      cout<<"a is smallest";
  }
return 0;
}

c++ program result

Steps to create a simple c++ program:
 

(1) Creating Source code

Creating includes typing and editing the valid C++ code as per the rules followed by the C++ Compiler.

(2) Saving process:

After typing, the source code should be saved with the extension .cpp

(3) Compilation

This is an important step in constructing a program. In compilation, compiler links the library files with the source code and verifies each and every line of code. If any mistake or error is found, it will throw error message. If there are no errors then it translates the source code into machine readable object file with an extension .obj

(4) Execution

In this stage, the object file becomes an executable file with extension .exe.

Steps to create a source code:


*need for #include <iostream>

using namespace std;

int main()

Usually all C++ programs begin with include statements starting with a #. The symbol # is a directive for the pre-processor. That means, these statements #include <iostream> statement tells the compiler’s pre-processor to include the header file “iostream” in the program. The header file iostream should included in every C++ program to implement input/output functionalities.

 If you fail to include iostream in your program, an error message will occur on cin and cout.

The line using namespace std; tells the compiler to use standard namespace. Namespace collects identifiers used for class, object and variables.

Every C++ program must have a main function. 

The main( ) function is the starting point where all C++ programs begin their execution.

Therefore, the executable statements should be inside the main( ) function.

syntax of if else statement:

if(condition)

{
 //body of the statement;
}

Explanation of if else statement:

The if else statement evaluates a condition; if the condition is true then the statement inside the if part will be executed; that is the statement inside the else part will be skipped while, if the condition evaluates to false then the statement inside else part will be executed that is the statement inside if part will be skipped.