desislava_topuzakova

06. Vowels Sum

Jan 31st, 2022
941
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     string text;
  8.     getline(cin, text);
  9.     //сумата от стойностите на гласните букви
  10.     //всяка буква -> проверка дали е гласна (a, e, i, o, u) -> добавям към сумата нейната стойност
  11.     int sum = 0; //сумата от стойностите на гласните букви
  12.     for (int position = 0; position <= text.length() - 1; position++)
  13.     {
  14.         char currentSymbol = text[position];
  15.         //проверка
  16.         if (currentSymbol == 'a')
  17.         {
  18.             //стойността на а = 1
  19.             sum = sum + 1;
  20.             //sum += 1;
  21.  
  22.         }
  23.         else if (currentSymbol == 'e')
  24.         {
  25.             sum = sum + 2;
  26.             //sum += 2;
  27.  
  28.         }
  29.         else if (currentSymbol == 'i')
  30.         {
  31.             sum = sum + 3;
  32.             //sum += 3;
  33.         }
  34.         else if (currentSymbol == 'o')
  35.         {
  36.             sum = sum + 4;
  37.             //sum += 4;
  38.         }
  39.         else if (currentSymbol == 'u')
  40.         {
  41.             sum = sum + 5;
  42.             //sum += 5;
  43.         }
  44.     }
  45.  
  46.     cout << sum << endl;
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment