C++ Primer-第五章习题

5.9

 1 #include <iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     
 6     unsigned vowelCnt = 0, otherCnt = 0;
 7     char ch;
 8     while (cin >> ch) {
 9         if (ch == 'a') {
10             ++vowelCnt;
11         }
12         else if (ch == 'e') {
13             ++vowelCnt;
14         }
15         else if (ch == 'i') {
16             ++vowelCnt;
17         }
18         else if (ch == 'o') {
19             ++vowelCnt;
20         }
21         else if (ch == 'u') {
22             ++vowelCnt;
23         }
24         else {
25             ++otherCnt;
26         }
27         
28     }
29     cout<<"Number of vowel: "<<vowelCnt<<"\n"
30         <<"Number of other: "<<otherCnt<<"\n"<<endl;
31     system("pause");
32     return 0;
33 }
View Code

猜你喜欢

转载自www.cnblogs.com/archerzon/p/9691529.html