C or C++ program to count the occurrences of two consecutive vowels

#include <iostream>
#include <string>

bool isVowel(char c) {
    c = tolower(c);
    return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');
}

int countConsecutiveVowels(const std::string& str) {
    int count = 0;
    for (size_t i = 0; i < str.length() - 1; i++) {
        if (isVowel(str[i]) && isVowel(str[i + 1])) {
            count++;
        }
    }
    return count;
}

int main() {
    std::string str;
    std::cout << "Enter a string: ";
    std::getline(std::cin, str);

    int occurrences = countConsecutiveVowels(str);
    std::cout << "Occurrences of consecutive vowels: " << occurrences << std::endl;

    return 0;
}

Leave a Comment