Advertisement
cwchen

Calculate vowels with Cpp

May 28th, 2015
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using std::cerr;
  5. using std::cout;
  6. using std::endl;
  7.  
  8. int main(int argc, char *argv[]) {
  9.   if (argc < 2) {
  10.     cerr << "Usage: " << argv[0] << " word01 word02 word03 ..." << endl;
  11.     exit(EXIT_FAILURE);
  12.   }
  13.  
  14.   unsigned count = 0;
  15.   for (unsigned i = 1; i < argc; i++) {
  16.     // loop by pointer
  17.     for (char *p = argv[i]; *p != '\0'; p++) {
  18.       switch (*p) {
  19.       case 'a':
  20.       case 'A':
  21.       case 'e':
  22.       case 'E':
  23.       case 'i':
  24.       case 'I':
  25.       case 'o':
  26.       case 'O':
  27.       case 'u':
  28.       case 'U':
  29.     count++;
  30.     break;
  31.       }
  32.     }
  33.   }
  34.  
  35.   cout << count << endl;
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement