+ 2
Input character
Write a C++ program to check whether input character is a vowel,consonant, integer or special character using else-if ladder only.
4 Answers
+ 1
C++ has no syntax to write in-between in a single operator expression so for example : 'a' < a < 'e' so it is syntactically right but it is evaluated as ( 'a'< a )< 'e' => 0 < 'e' => 1 (true) for input a number . It does not mean to " a in between 'a' and 'e'. " The correct way is ( 'a'<a && a< 'e' )
Hope it helps.
+ 2
Hi! Please, show us your code attempt! Thx!
+ 2
#include <iostream>
using namespace std;
int main()
{ char a;
cout<<"enter a character ";
cin>>a;
if(a=='a' || a=='e' || a=='i' || a=='o' || a=='u')
{
cout<<"input is a vowel";
}
else if(a=='A' || a=='E' || a=='I' || a=='O' || a=='U')
{
cout<<"input is a vowel";
}
else if('a'<a<'e'||'e'<a<'i'||'i'<a<'o'||'o'<a<'u')
{
cout<<"input is a consonant";
}
else if('A'<a<'E'||'E'<a<'I'||'I'<a<'O'||'O'<a<'U')
{
cout<<"input is a consonant";
}
else if(0<a<9)
{
cout<<"input is an integer";
}
return 0;
}
Plz help it is showing as consonant even if I enter integer
+ 2
Thank u so much bro!!!!!!!!
Thank uuuuuuuuđđ»đđ»