+ 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.

9th Jun 2021, 3:41 PM
Viraj
Viraj - avatar
4 Réponses
+ 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.
9th Jun 2021, 4:26 PM
Jayakrishna 🇮🇳
+ 2
Hi! Please, show us your code attempt! Thx!
9th Jun 2021, 3:42 PM
Yaroslav Vernigora
Yaroslav Vernigora - avatar
+ 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
9th Jun 2021, 3:50 PM
Viraj
Viraj - avatar
+ 2
Thank u so much bro!!!!!!!! Thank uuuuuuuu🙏🏻🙏🏻
9th Jun 2021, 4:45 PM
Viraj
Viraj - avatar