Skip to content

Commit

Permalink
Update ex5_10.cpp
Browse files Browse the repository at this point in the history
The switch statemen more better.
  • Loading branch information
pezy committed Oct 14, 2014
1 parent c526c47 commit 7c47a9d
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions ch05/ex5_10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,40 @@

using std::cin; using std::cout; using std::endl;

int main(void)
int main()
{
char c;
int aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0;
while (cin >> c)
{
if (c == 'a' || c == 'A')
++aCnt;
else if (c == 'e' || c == 'E')
++eCnt;
else if (c == 'i' || c == 'I')
++iCnt;
else if (c == 'o' || c == 'O')
++oCnt;
else if (c == 'u' || c == 'U')
++uCnt;
}
cout << "Num of vowel a(A) : " << aCnt << endl;
cout << "Num of vowel e(E) : " << eCnt << endl;
cout << "Num of vowel i(I) : " << iCnt << endl;
cout << "Num of vowel o(O) : " << oCnt << endl;
cout << "Num of vowel u(U) : " << uCnt << endl;
return 0;
unsigned aCnt = 0, eCnt = 0, iCnt = 0, oCnt = 0, uCnt = 0;
char ch;
while (cin >> ch)
switch (ch)
{
case 'a':
case 'A':
++aCnt;
break;
case 'e':
case 'E':
++eCnt;
break;
case 'i':
case 'I':
++iCnt;
break;
case 'o':
case 'O':
++oCnt;
break;
case 'u':
case 'U':
++uCnt;
break;
}

cout << "Number of vowel a(A): \t" << aCnt << '\n'
<< "Number of vowel e(E): \t" << eCnt << '\n'
<< "Number of vowel i(I): \t" << iCnt << '\n'
<< "Number of vowel o(O): \t" << oCnt << '\n'
<< "Number of vowel u(U): \t" << uCnt << endl;

return 0;
}

0 comments on commit 7c47a9d

Please sign in to comment.