Guest User

Untitled

a guest
Nov 18th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstdlib>
  4. using namespace std;
  5.  
  6.  
  7. void mypause(void);
  8. int specialCounter(char *foo, int &consonants);
  9.  
  10. bool isVowel(char c);
  11. void menu();
  12.  
  13. int main()
  14. {
  15.     const int BUFFER = 251;        //Array size
  16.     char str[BUFFER];      // To hold the string
  17.     char decision;
  18.     int consonants;
  19.     bool flag = true;
  20.  
  21.     cout << "Please enter a string (up to 250 characters): " << endl;
  22.     cin.getline(str, BUFFER);
  23.  
  24.     int vowels = specialCounter(str, consonants);
  25.  
  26.     do
  27.     {
  28.         menu();
  29.         cin >> decision;
  30.         switch(decision)
  31.         {
  32.             case 'a':
  33.             case 'A':
  34.                 cout << vowels << " vowels\n\n";
  35.                 break;
  36.             case 'b':
  37.             case 'B':
  38.                 cout << consonants << " consonants\n\n";
  39.                 break;
  40.             case 'c':
  41.             case 'C':
  42.                 cout << vowels << " vowels\t " << consonants << " consonants\n\n";
  43.                 break;
  44.             case 'd':
  45.             case 'D':
  46.                 cout << "Please enter a string (up to 250 characters): " << endl;
  47.                 cout << "test";
  48.                 cin.getline(str, BUFFER);
  49.                 cout << "\ntest\n";
  50.                 vowels = specialCounter(str, consonants);
  51.                 cout << "If we made it here the vowels were counted somehow...\n";
  52.                 break;
  53.             case 'e':
  54.             case 'E':
  55.                 flag = false;
  56.                 break;
  57.             default:
  58.                 cout << "Invalid choice\n";
  59.         }
  60.         mypause();
  61.     }while(flag);
  62.  
  63.     return 0;
  64. }
  65.  
  66. void menu()
  67. {
  68.     cout << "ALPHABETIC VOWEL/CONSONANT COUNTER. NO NUMBERS ALLOWED NERD\n";
  69.     cout << "\nA) Count the number of vowels in the string\n";
  70.     cout << "B) Count the number of consonants in the string\n";
  71.     cout << "C) Count both the vowels and consonants in the string\n";
  72.     cout << "D) Enter another string\n";
  73.     cout << "E) Exit the program\n\n";
  74. }
  75.  
  76. bool isVowel(char c)
  77. {
  78.  switch(c)
  79.  {
  80.     case 'a':
  81.     case 'A':
  82.     case 'e':
  83.     case 'E':
  84.     case 'i':
  85.     case 'I':
  86.     case 'o':
  87.     case 'O':
  88.     case 'u':
  89.     case 'U':
  90.     return true;
  91.  }
  92.    return false;
  93. }
  94. int specialCounter(char *foo, int &consonants)
  95. {
  96.     int vowels = 0;
  97.     consonants = 0;
  98.  
  99.     while (*foo)
  100.     {
  101.         isVowel(*foo) ? vowels++ : consonants++;
  102.         foo++;
  103.     }
  104.     return vowels;
  105. }
  106. void mypause(void)// Function mypause()
  107. {
  108.     system("pause");
  109.     return;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment