I'm new to programming but I have figured out how I could determine the number of vowels and consonants but I do not know how to display them. I don't know how to start.
The output should be something like this:
Digital Data
The vowel/s is/are "iiaaa" and its total is 5.
The consonant/s is/are "dgtldt" and its total is 9.
Hello!
Make an array of your vowels and consonants, so you can iterate throug them. The function tolower(int c) converts every ASCII char to lower case so you don't need to test it twice.
#include <iostream>
int main(int argc, char* argv[]) {
constint vowals[] = {'a','e', 'i','o','u', 0}; // vowels constant with an ending 0
char str[] = "Hallo"; // example string
int count = 0;
int i = 0;
int j = 0;
while(str[i] != 0) { // iterate throug the given string until reaching the null terminator of the string
while(vowals[j] != 0) { // iterate throug your vowels array until reaching the 0 terminater at the end of the array
if(tolower(str[i]) == vowals[j]) // convert char at pos i to lower case and compare it with our current vowel
count++; // increment amount of founded vowels
j++; // increment vowel loop iterator
}
j = 0; // reset vowel loop iterator
i++; // increment our string iterator
}
std::cout << "word: " << str << std::endl;
std::cout << "vowals: " << count << std::endl;
return 0;
}
Edit:
english != my native language
sorry for spelling errors -.-*
Thank you for your immediate response. I have already done the counting of the vowels and consonants, however I'm having a hard time displaying them out.
My output so far looks like this:
Digital Data
The vowel/s is/are " " and its total is 5.
The consonant/s is/are " " and its total is 9.
What I don't get mainly is how I would extract the vowels and the consonants from the inputted word. The output should be like the following:
Digital Data
The vowel/s is/are "iiaaa" and its total is 5.
The consonant/s is/are "dgtldt" and its total is 9.
...where it extracts the vowels/consonants and display them accordingly.