4.1.The if Statement

The if statement used for single condition that it’s will process when the if condition true and it will do nothing when condition false.

Syntax 1: The if condition with single statement

if(condition)
	statement 1;

Syntax 2: The if condition with multiple statements must be include { Opening Brace and } Closing Brace

if(condition)
{
	statement 1;
	...		
	statement n;
}

Example 1: The if condition with single statement

#include<iostream.h>
#include<conio.h>
void main()
{
	float score;
	cout<<"Enter Score: ";            cin>>score;
	if(score>=50)
		cout<<"Passed";
	getch();
}

Example 2: The if condition with multiple statements

#include<iostream.h>
#include<conio.h>
void main()
{
	float score;
	cout<<"Enter Score: ";            cin>>score;
	if(score>=50)
        {
		cout<<"Passed\n";
                cout<<"Congratulations";
        }
	getch();
}
Suggest Edit