The If/Else statement in C++

Posted By: Java Examples - 6:39 AM

Share

& Comment

The if else statement is a type of control structure. A control structure is a instruction, statement or group of statements which determines the sequence of execution of other statements. The basic operation of if else statement is that a statement or group of statements is executed under if, if the value of expression is true and if the expression is false, statements under else are evaluated. In C++ language, zero is false everything else is true. Statement associated either with if or else are executed not both group of statements are executed. The else clause is optional. 


The general form of if else statement is:-
if (expression){
statement;
}
else{
statement;
}

Or

if (expression){
statement;
}

The curly braces mark the beginning and the end statements under if and else.

Here is a program which illustrates the functioning of if else statement :

#include
using namespace std;

void result(int x)
{
if(x>100 | x<0 b="b">
cout<<"Your Mark is Wrong!"<
else if(x>=75)
cout<<" RESULT IS A "<
else if(x>=65)
cout<<" RESULT IS B "<
else if(x>=55)
cout<<" RESULT IS C "<
else if(x>=45)
cout<<" RESULT IS D "<
else if(x<45 b="b">
cout<<" RESULT IS E "<

}

void main()
{
int x;
cout<<"Enter your mark"<
cin>>x;
result(x);
system("PAUSE");
}

The result of the program is :


Enter your mark
65
 RESULT IS B
Press any key to continue . . .

About Java Examples

I’m passionate about Web Development and Programming and I go to extreme efforts to meet my passion. I’m a believer of learning the fundamentals first. I try to understand everything little bit more than the average.

0 comments :

Post a Comment

Copyright © 2016 C++ Examples ACHCHUTHAN.ORG. Designed by Templateism .