+ 4

In the code below i have used Switch statement. But i want to use(if else) istead of Switch, What changes should i make?

#include <iostream> using namespace std; int main() { char letter; cin>>letter; switch(letter*(letter>='a' && letter<='z')){ case 'a': case 'e': case 'i': case 'o': case 'u': cout<<"you entered a vowel"<<endl; break; case 0:cout<<"that is not a small letter"<<endl; break; default:cout<<"you entered a constant"<<endl; } return 0; }

8th Sep 2017, 2:25 PM
RiGeL
RiGeL - avatar
5 Answers
+ 5
https://code.sololearn.com/cr6DaoUcB8IC/#cpp #include <iostream> using namespace std; int main() { char letter; cin>>letter; char ltr = letter*(letter>='a' && letter<='z'); // IF-ELSE STATEMENTS if( ltr == 'a' || ltr == 'e' || ltr == 'i' || ltr == 'o' || ltr == 'u') { cout<<"you entered a vowel"<<endl; } else if(ltr == 0) { cout<<"that is not a small letter"<<endl; } else { cout<<"you entered a constant"<<endl; } return 0; }
8th Sep 2017, 2:35 PM
AgentSmith
+ 5
https://msdn.microsoft.com/en-us/library/y34a3dk2.aspx if ( expression ) statement1 [else statement2]
8th Sep 2017, 2:26 PM
AgentSmith
+ 3
@Netkos Ent THANK YOU SO MUCH!
8th Sep 2017, 3:29 PM
RiGeL
RiGeL - avatar
+ 3
You're more than welcome RiGel. Best of luck with your programming journey.
8th Sep 2017, 4:14 PM
AgentSmith
+ 2
@Netkos Ent thank you i appreciate your encouragement!😊
8th Sep 2017, 4:37 PM
RiGeL
RiGeL - avatar