Advertisement
Guest User

Vowel number

a guest
Apr 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main () {
  4.     using std::cin;
  5.    
  6.     int amount = 0;
  7.     cin >> amount;
  8.    
  9.     auto is_vowel = [](char letter) {
  10.         for (char a : "aieouy")
  11.             if (letter == a) return 1;
  12.         return 0;
  13.     };
  14.    
  15.    
  16.     // Cycle-related block
  17.     char ch;
  18.     int number_of_vowels;
  19.    
  20.     for (int i = 0; i < amount; i++) {
  21.         cin >> ch;
  22.         number_of_vowels = 0;
  23.        
  24.             while (ch != '\n') {
  25.                 number_of_vowels += is_vowel(ch); // is_vowel returns 0/1
  26.                 cin.get(ch); // moving cursor right
  27.             }
  28.         cin.get();  
  29.         // std::cout << number_of_vowels << " ";
  30.         std::cout << i << " "; // for testing purposes
  31.     }
  32.    
  33.     return 0;    
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement