Friday, April 16, 2010

Use of switch Statements

#include<iostream.h>
#include<conio.h>
 void main()
 {
 clrscr();
 int speed;
 cout<<"1. for 0-20\n";
 cout<<"2. for 20-60\n";
 cout<<"3. for 60-100\n";
 cout<<"4. for >100\n";
 cout<<"enter speed\n";
 cin>>speed;
 switch(speed)
 {
 case 1:
 cout<<"slow speed\n";
 break;
 case 2:
 cout<<"average\n";
 break;
 case 3:
 cout<<"fast\n";
 break;
 case 4:
 cout<<"danger\n";
 break;
 default:
 cout<<"invalid choice";
 }
 getch();
 }

No comments:

Post a Comment