Write a C++ Program to Check Whether a character is Vowel or Consonant.

Answers were Sorted based on User's Feedback



Write a C++ Program to Check Whether a character is Vowel or Consonant...

Answer / hr

Solution:
/* C++ Program to Check Whether a character is Vowel or Consonant */
#include <iostream>
using namespace std;
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
cout << "Enter any character to check :: ";
cin >> c;
// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true
if (isLowercaseVowel || isUppercaseVowel)
{
cout<<"
The Entered Character [ "<<c<<" ] is a Vowel.
";
}
else
{
cout<<"
The Entered Character [ "<<c<<" ] is a Consonant.
";
}
return 0;
}
Output:
/* C++ Program to Check Whether a character is Vowel or Consonant */
Enter any character to check :: u
The Entered Character [ u ] is a Vowel.
Process returned 0

Is This Answer Correct ?    0 Yes 0 No

Write a C++ Program to Check Whether a character is Vowel or Consonant...

Answer / hr

Solution:
/* C++ Program to Check Whether a character is Vowel or Consonant */
#include <iostream>
using namespace std;
int main()
{
char c;
int isLowercaseVowel, isUppercaseVowel;
cout << "Enter any character to check :: ";
cin >> c;
// evaluates to 1 (true) if c is a lowercase vowel
isLowercaseVowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
// evaluates to 1 (true) if c is an uppercase vowel
isUppercaseVowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');
// evaluates to 1 (true) if either isLowercaseVowel or isUppercaseVowel is true
if (isLowercaseVowel || isUppercaseVowel)
{
cout<<"
The Entered Character [ "<<c<<" ] is a Vowel.
";
}
else
{
cout<<"
The Entered Character [ "<<c<<" ] is a Consonant.
";
}
return 0;
}
Output:
/* C++ Program to Check Whether a character is Vowel or Consonant */
Enter any character to check :: u
The Entered Character [ u ] is a Vowel.
Process returned 0

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ Interview Questions

Discuss about iteration statements in C++ .

0 Answers   Agilent,


How to run C++ program in cmd

0 Answers  


What is the difference between virtual functions and pure virtual functions?

1 Answers  


What are string library functions(syntax).

0 Answers   Accenture,


What is Coupling?

0 Answers   Cap Gemini,


Write a C++ Program to Display Number (Entered by the User).

1 Answers  


What is an algorithm (in terms of the STL/C++ standard library)?

0 Answers   Amazon,


What is a memory leak in C++?

0 Answers   Agilent,


Execute the qsort () in c/sort() in c++ library or your own custom sort which will sort any type of data on user defined criteria.

0 Answers   Adobe,


Write a program to input an integer from the keyboard and display on the screen “WELL DONE” that many times.

1 Answers  


What is the purpose of a constructor? Destructor?

0 Answers   Amazon,


Question on Copy constructor.

0 Answers   Alter,


Categories