+ 2

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, 1:19 PM
RiGeL
RiGeL - avatar
9 Antworten
+ 6
Here : #define islower(a) a>='a' && a<='z' if( islower(letter) ) { if (letter == 'a' || letter == 'e' || letter == 'i' || letter == 'o' || letter == 'u') cout<<"User entered a Vowel"<<endl; else cout<<"User entered a Consonant"<<endl; } else cout<<"Invalid Input - Not a Small Letter";
8th Sep 2017, 1:36 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
@Daniel thank you alot
8th Sep 2017, 1:41 PM
RiGeL
RiGeL - avatar
+ 4
@RiGel Just to check if the input was a small letter or not. If its not, we'll have to display an error that the input is not a small letter. Though we have a predefined function for this in the header <cctype>, with the same name, I redefined it so that you can easily understand what its supposed to do.
9th Sep 2017, 3:41 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 3
@Kinshuk thank you alot
8th Sep 2017, 1:41 PM
RiGeL
RiGeL - avatar
+ 2
first an if to check if letter is or not (else) small if first if is correct then check with an if with OR conditions to check if letter is a vowel
8th Sep 2017, 1:33 PM
Daniel
Daniel - avatar
+ 2
@kinshuk thank you for ur answer i hope its not late too ask..but what is (islower) exactly used for?
8th Sep 2017, 2:21 PM
RiGeL
RiGeL - avatar
+ 2
Check the first line of his code ;-)
8th Sep 2017, 2:59 PM
Daniel
Daniel - avatar
+ 2
@Daniel Thank you
8th Sep 2017, 3:31 PM
RiGeL
RiGeL - avatar
+ 2
@Kinshuk THANK YOU ALOT!
9th Sep 2017, 6:25 AM
RiGeL
RiGeL - avatar