Re write the following code fragment using one switch statement
if (ch = = ‘E’|| ch= = ‘e’)
cout<<" this is either the value of ‘E’ or ‘e’";
else if (ch = = ‘A’|| ch= = ‘a’)
cout<<" this is either the value of ‘A’ or ‘a’";
else if (ch = = ‘r’|| ch= = ‘i’)
cout<<" this is either the value of ‘i’ or ‘r’";
else
cout<<" Enter the correct choice";
#include <iostream>
using namespace std;
int main() {
char ch='e';
switch(ch){
case 'E':
case 'e':
cout<<" this is either the value of 'E' or 'e'";
break;
case 'A':
case 'a':
cout<<" this is either the value of 'A' or 'a'";
break;
case 'i':
case 'r':
cout<<" this is either the value of 'i' or 'r'";
break;
default:
cout<<" Enter the correct choice";
break;
}
cin>>ch;
return 0;
}
Comments
Leave a comment