-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringop.cpp
8000
More file actions
29 lines (25 loc) · 788 Bytes
/
stringop.cpp
File metadata and controls
29 lines (25 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <cctype>
int main() {
const int max_length {100};
char text[max_length] {};
std::cout << "Enter a line of text:" << std::endl;
//read a line of characters including spaces
std::cin.getline(text, max_length);
std::cout << "You entered:\n" << text << std::endl;
size_t vowels {};
size_t consonants {};
for (int i {}; text[i] != '\0'; ++i) {
if (std::isalpha(text[i])) {
switch (std::tolower(text[i])) {
case 'a': case 'e': case 'u':
++vowels;
break;
default:
++consonants;
}
}
}
std::cout << "Your input contained " << vowels << " vowels and "
<< consonants << " consonants." << std::endl;
}