Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import packages
- #include <iostream>
- #include <string>
- #include <cctype>
- // import standard c++ library
- using namespace std;
- int main()
- {
- // declare variables
- string input,
- lowerInput = "",
- newString = "";
- int vowels = 0;
- // prompt user for input
- cout << "Please enter a string.\n";
- cin >> input;
- // determine if user input equals "end"
- for (int k = 0; k < input.length() - 1; k++)
- {
- lowerInput += tolower(input.at(k));
- if (lowerInput == "end")
- return 0;
- }
- // find vowels within string
- for (int i = 0; i < input.length() - 1; i++)
- {
- if (lowerInput.at(i) == 'a' || 'e' || 'i' || 'o' || 'u')
- {
- // append underscore after vowel
- newString += input.at(i) + "_";
- vowels++;
- }
- }
- // output amount of vowels and resulting string
- cout << "Vowels: " << vowels << endl
- << "Modified string: " << newString << endl;
- // exit program
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement