Answer to Question #185976 in C++ for shuvo

Question #185976
”a”, ”e”, ”i”, ”o”, and ”u” are called vowels. word is a variable of type string.
Assume that a word is read from the keyboard and assigned to this variable. Write a
for loop to count the number of vowels in a word. Only write the for loop. Those who
write more than required number of lines, are going to lose points.
1
Expert's answer
2021-05-01T17:01:42-0400
#include <iostream>
#include <string>

int main() {
    const std::string vowels = "aeiou";
    std::string input;
    std::cin >> input;
    int counter = 0;
    for (size_t i = 0; i < input.size(); i++) {
        counter += vowels.find(input[i]) != std::string::npos;
    }
    std::cout << counter;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS