Advertisement
hiker43

pigLatin

Sep 1st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using std::cout;
  5. using std::cin;
  6.  
  7.  
  8. int findFirstVowel(char word[])
  9. {
  10.     for (int i=0; i < strlen(word); i++)
  11.     {
  12.         if (word[i]=='a' || word[i]=='e' || word[i]=='i' || word[i]=='o' || word[i]=='u' || (word[i]=='y' && i!=0))
  13.  
  14.         return i;
  15.  
  16.     }
  17. }
  18. int main()
  19. {
  20.     char word[20];
  21.     char pigLatin[20];
  22.  
  23.     cout<<"Vnesi zbor po sopstven izbor:\t";
  24.     cin>>word;
  25.  
  26.     int i= findFirstVowel(word);
  27.     if(i == 0)
  28.     {
  29.      strcpy(pigLatin, word);
  30.      strcat(pigLatin, "way");
  31.     }
  32.     else
  33.    {
  34.     int k=0;
  35.     for(int j = i; j < strlen(word); j++)
  36.     {
  37.         pigLatin[k++]=word[j];
  38.     }
  39.         pigLatin[k]='\0';
  40.         strncat(pigLatin, word, i);
  41.         strcat(pigLatin, "ay");
  42.     }
  43.         cout<<"pigLatin of "<<word<< " is "<<pigLatin;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement