dstamatova

StringVowels

Dec 30th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int isVowel(char character)
  6. {  
  7.     //character = character - 32;
  8.     string vowels = "aeiou";
  9.     int n = vowels.length();
  10.     for (int i = 0; i < n; i++)
  11.     {
  12.         if (character == vowels[i])
  13.         {
  14.             cout << vowels[i];
  15.             return 1;
  16.         }
  17.         else
  18.         {
  19.             cout << vowels[i];
  20.             return 0;
  21.         }
  22.     }
  23. }
  24.  
  25. int countVowels(string stringMy)  // function that returns the count of vowels
  26. {
  27.     int count = 0;
  28.     for (int i = 0; i < stringMy.length(); i++)
  29.     {
  30.         if (isVowel(stringMy[i]))  // check if character is vowel
  31.             count ++;
  32.     }
  33.     return count;
  34. }
  35.  
  36. int main()
  37. {
  38.     string  stringMy = "educative";
  39.     cout << countVowels(stringMy);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment