[学习笔记]C++17学习第9天
```# include <iostream>
# include <cctype>
//c++17
using namespace std;
int main()
{
const int max_length{100};
char text{};
cout << "Enter a line of text: " << endl;
cin.getline(text, max_length);
cout << "You entered:\n" << text << endl;
size_t vowels{};
size_t consonants {};
for(size_t i{}; text !='\0';++i)
{
if (isalpha(text))
{
switch(tolower(text))
{
case 'a': case 'e': case 'i': case 'o': case 'u':
++vowels;
break;
default:
++consonants;
break;
}
}
}
cout << "Your input contained " << vowels << " vowels and " << consonants << " consonants.\n";
}
```
建议switch不要你那样写
而是 switch()
case :
case :
case :
.... cout输出一般用endl来取代\n 支持一下!坚持就是胜利 好好学习,天 天向上。 认真抄楼主作业。感谢分享
页:
[1]