Do While and Switch Statement Demo
This is a simple program that demonstrate the DO WHILE and SWITCH Statement. Enjoy!
Final Output
#include <iostream>
using namespace std;
int main()
{
char letter;
int choices;
do
{
letter='n';
cout<<endl<<"SELECT MENU";
cout<<endl<<"[ 1 ] Choice A";
cout<<endl<<"[ 2 ] Choice B";
cout<<endl<<"[ 3 ] Choice C";
cout<<endl<<"[ 4 ] Exit Choice"<<endl;
cout<<endl<<"Your choice:";
cin>>choices;
switch(choices)
{
case 1: cout<<endl<<"You Select A";
break;
case 2: cout<<endl<<"You Select B";
break;
case 3: cout<<endl<<"You Select C";
break;
case 4: cout<<endl<<"Exit the program";
return 0;
default: cout<<endl<<"Invalid choice";
letter = 'n';
}
}while(letter == 'n');
return 0;
}
Final Output
#include <iostream>
using namespace std;
int main()
{
char letter;
int choices;
do
{
letter='n';
cout<<endl<<"SELECT MENU";
cout<<endl<<"[ 1 ] Choice A";
cout<<endl<<"[ 2 ] Choice B";
cout<<endl<<"[ 3 ] Choice C";
cout<<endl<<"[ 4 ] Exit Choice"<<endl;
cout<<endl<<"Your choice:";
cin>>choices;
switch(choices)
{
case 1: cout<<endl<<"You Select A";
break;
case 2: cout<<endl<<"You Select B";
break;
case 3: cout<<endl<<"You Select C";
break;
case 4: cout<<endl<<"Exit the program";
return 0;
default: cout<<endl<<"Invalid choice";
letter = 'n';
}
}while(letter == 'n');
return 0;
}
Do While and Switch Statement Demo
Reviewed by code-dev
on
1:42 PM
Rating:
No comments: