C++ show vowel and consonant and count it

前端 未结 3 1026
南旧
南旧 2021-01-26 01:47

When user input number from 1 - 26 (which mean a to z), how to show the the letter and count how many vowel and consonant inside it.

Example: U

3条回答
  •  温柔的废话
    2021-01-26 02:09

    To show the letters, you can use a for loop, using a char as index.

    int n = 13;
    unsigned int vowel = 0;
    unsigned int consonant = 0;
    int a = (int)'a';
    for (char letter = 'a'; (int)letter < a + n; letter++) {
        cout << letter << " ";
        if (is_vowel(letter)) vowel++;
        else consonant++;
    }
    cout << std::endl << "vowels: "<< vowel << " consonants: " << consonant << std::endl;
    

    So, you must implement the is_vowel method.

提交回复
热议问题