Swith….Case Statements in C++

by Nideesh C on May 7, 2011 · 0 comments

in C++




The switch…case construct provides a better way of representing the conditions, as it reduces the complexity in code and easier to debug and understand.

Syntax:

Switch(<Variable>)

{

case<Variable1>;

{

Statements;

break;

}

case<Value2>;

{

Statements;

break;

}

.

.

default:

{

Statements;

}

}

/*———————————————————————-*/

#include<iostream.h>

#include<conio.h>

void main()

{

char vowel;

cout<<”Enter a charactor value :”;

cin>>vowel;

switch(vowel)

{

case ‘a’:

{

cout<<”Vowel”;

break;

}

case ‘e’:

{

cout<<”Vowel”;

break;

}

case ‘i’;

{

cout<<”Vowel”;

break;

}

case ‘o’;

{

cout<<”Vowel”;

break;

}

case ‘u’

{

cout<<”Vowel”;

break;

}

default:

cout<<”Not a vowel”;

}

getch();

}

/*————————————————————————–*/

Output: 1

Enter a character value : a

Vowel

Output: 2

Enter a character value :z

Not a vowel

See also: C++ Program – Vowel checking

 

 

 




Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. Nested If …Else Statements in C++
  2. if……else statements in C++
  3. Nested if statements in C++
  4. C program – Morse code to text conversion and vice-versa.
  5. C Program to convert the lower case letters to upper case and vice-versa

Leave a Comment

Previous post:

Next post: