Read the question, write C++ on the right, then Run or Check.
QuestionHint and solution stay closed until you open them
Read one word and print how many vowels (a, e, i, o, u) it contains.
Count both cases — lowercase each character before testing.
Input. One line: a word.
Output. One integer: the vowel count.
Examples
Input
Programming
Output
3
Input
sky
Output
0
Hint
- Loop over the characters with for (char ch : word).
- #include <cctype>, then std::tolower to normalise case before comparing.
Show correct code
Peek only after you have tried. You can still Check your own version.
#include <iostream>
#include <string>
#include <cctype>
int main() {
std::string word;
std::cin >> word;
int count = 0;
for (char ch : word) {
char l = std::tolower((unsigned char)ch);
if (l == 'a' || l == 'e' || l == 'i' || l == 'o' || l == 'u') count++;
}
std::cout << count << "\n";
return 0;
}
main.cppC++17 · g++ · Ctrl + Enter runs
ResultIdle
Run to see output. Check grades the tests.