+ 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; }
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";
+ 4
@Daniel thank you alot
+ 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.
+ 3
@Kinshuk thank you alot
+ 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
+ 2
@kinshuk thank you for ur answer i hope its not late too ask..but what is (islower) exactly used for?
+ 2
Check the first line of his code ;-)
+ 2
@Daniel Thank you
+ 2
@Kinshuk THANK YOU ALOT!