The If/Else statement in C++

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){


if (expression){

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 :

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"<

The result of the program is :

Enter your mark
Press any key to continue . . .

No comments:

Post a Comment

Copyright © 2010-2019 C++ Examples

Designed by Templateism. Built with Blogger Templates.