Question: Write a program that prompts the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If

Write a program that prompts the user to provide a single character from the alphabet. Print Vowel or Consonant, depending on the user input. If the user input is not a letter (between a and z or A and Z), or is a string of length > 1, print an error message stating Invalid entry.

hint

  • You can use comparisons to check if the input is invalid first:
    • For example, if the input is less than "A" or greater than "z", or if the length of the input is greater than 1, then it is an invalid entry.
  • Else, if it is a valid letter, then check if it is a vowel by comparing it against the vowels. If it is not a vowel, then it is a consonant.
    • Make sure to check for both upper and lowercase vowels. See the next comment below for how to check for all of the upper and lowercase vowels in a single if statement condition

Note

For this problem and future problems, remember that you can always combine multiple boolean expressions together inside of your conditions. For example, if you were checking if the letter was an "a", "e", or "i", you could do this:

  • if (letter == "a" || letter == "e" || letter == "i")
    • You can expand on this to include more checks in the same if statement condition (e.g., the rest of the lowercase and uppercase vowels).
  • Just be careful of whether you want to use the boolean AND (&&) or the boolean OR (||) to combine the

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!