Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <sstream>
- #include <vector>
- #include <climits>
- #include <cctype>
- using namespace std;
- void String(const string aLine, vector<string>& intermediate);
- int main()
- {
- //starting up vars
- bool vowelConfirm = false;
- unsigned short i = 0, j = 0;
- string message = "";
- string interWord = "";
- string outputText = "";
- string yesno = "Y";
- string vowels = "aeiou";
- vector<string> intermediate;
- // loop to run as long as yesno is Y or y
- while(yesno == "Y" || yesno == "y")
- {
- outputText = "";
- intermediate.clear();
- //welcome message
- cout << "Welcome to the pig latin converter program!\n"
- << "Input word or phrase: \n";
- getline(cin, message);
- String(message, intermediate);
- vector<string>::iterator kitkat;
- for(i = 0, kitkat = intermediate.begin(); kitkat != intermediate.end(); i++, kitkat++)
- {
- string test = *kitkat;
- //tests for vowels at start
- vowelConfirm = false;
- if(test.length() < 2)
- {
- cerr << "The word " << test << " is too short!" << endl;
- }
- for(j = 0; j < vowels.length(); j++)
- {
- if(tolower(test[0]) == vowels[j])
- {
- vowelConfirm = true;
- interWord = test + "ay ";
- outputText += interWord;
- }
- }
- if(! vowelConfirm)
- {
- interWord = test.substr(1);
- interWord += test[0];
- interWord += "ay ";
- outputText += interWord;
- }
- }
- cout << "Your converted text is:\n"
- << outputText << endl;
- //reloop code
- cout << "Do you have another phrase to convert?(Y/N):";
- cin >> yesno;
- cin.ignore(INT_MAX, '\n');
- }
- //exit text
- cout << "Have a nice day! Exiting...\n";
- return 0;
- }
- //function for vec.push_back
- void String(const string aLine, vector<string>& intermediate)
- {
- string buffer;
- stringstream ss(aLine);
- while(ss >> buffer)
- {
- intermediate.push_back(buffer);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement