j

Sunday, 13 December 2015

what is if-else-if Statement



if-else-if Statement
if-else-if statement can be used to choose one block of statements from multiple statements. It is used when there are many options and only one block of statements should be executed on the basis of a condition.
Syntax:
if(condition)
{
Block 1;
}
else if(condition)
{
Block 2;
}
else if(condition)
{
Block 3
}
.
.
else
{
Block N;
}

  
Write a program that input choice 1 to 7 if user enter 1 then display Sunday , if enter 2 Monday and so on
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int ch;
cout<<"Enter your Choice 1 to 7 :";
cin>>ch;
if(ch==1)
cout<<"Sunday";
else if(ch==2)
cout<<"Monday";
else if(ch==3)
cout<<"Tuesday";
else if(ch==4)
cout<<"Wednesday";
else if(ch==5)
cout<<"Thirsday";
else if(ch==6)
cout<<"Friday";
else if(ch==7)
cout<<"Saturday";
else
cout<<"Invalid Input!";
getch();
}
 

Subscribe to this Blog via Email :