Created
April 28, 2019 09:05
-
-
Save kylethedeveloper/fe14c9f0982c31a94b37071c15710f5f to your computer and use it in GitHub Desktop.
Simple program that prints out the number of letters, vowels and consonants in a word.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
int main() { | |
int vowel; | |
bool space = true; | |
string word; | |
cout << "Enter a word (do not use numbers or special characters): "; | |
while(space) { | |
vowel = 0; | |
getline(cin, word); | |
for (int i = 0; i < word.size(); i++) { | |
if (word[i] < 'a' || word[i] > 'z') { | |
space = true; | |
cout << "Please enter without a number, special character and space: "; | |
break; | |
} | |
else { | |
space = false; | |
if (word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'o' || word[i] == 'u') | |
vowel++; | |
} | |
} | |
} | |
cout << word << " is " << word.size() << " letters." << endl; | |
cout << word << " contains " << vowel << " vowels and " << word.size()-vowel << " consonants." << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment