Advertisement
Guest User

Random

a guest
Mar 4th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. // import packages
  2. #include <iostream>
  3. #include <string>
  4. #include <cctype>
  5.  
  6. // import standard c++ library
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.     // declare variables
  12.     string input,
  13.            lowerInput = "",
  14.            newString = "";
  15.     int vowels = 0;
  16.  
  17.     // prompt user for input
  18.     cout << "Please enter a string.\n";
  19.     cin >> input;
  20.  
  21.     // determine if user input equals "end"
  22.         for (int k = 0; k < input.length() - 1; k++)
  23.         {
  24.             lowerInput += tolower(input.at(k));
  25.             if (lowerInput == "end")
  26.             return 0;
  27.         }
  28.  
  29.     // find vowels within string
  30.     for (int i = 0; i < input.length() - 1; i++)
  31.     {
  32.         if (lowerInput.at(i) == 'a' || 'e' || 'i' || 'o' || 'u')
  33.         {
  34.             // append underscore after vowel
  35.             newString += input.at(i) + "_";
  36.             vowels++;
  37.         }
  38.     }
  39.  
  40.     // output amount of vowels and resulting string
  41.     cout << "Vowels: " << vowels << endl
  42.          << "Modified string: " << newString << endl;
  43.  
  44.     // exit program
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement