dimanche 4 avril 2021

How to output correct English articles for user input? [closed]

I am creating a program where it needs to output the correct English article for the noun the user inputs into the program. For example, an user types in egg and it will output "an egg." If you type in book, then it will output "a book." Here is what I have below, and the 2nd problem is that my code doesn't output the full word and only the vowel/consonant.

#include <iostream>
using namespace std;

int main() {
    char noun, article;
    int isLowercaseVowel, isUppercaseVowel;

    cout << "Enter a noun: ";
    cin >> noun;

    
    isLowercaseVowel = (article == 'a' || article == 'e' || article == 'i' || article == 'o' || article == 'u');

    
    isUppercaseVowel = (article == 'A' || article == 'E' || article == 'I' || article == 'O' || article == 'U');

    
    if (!isalpha(noun))
      printf("Error! Non-alphabetic character.");
    else if (isLowercaseVowel || isUppercaseVowel)
        cout << article << " an " << noun;
    else
        cout << article << " a " << noun;

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire