Created
September 26, 2015 02:38
-
-
Save asterwolf/88deb1fb57dc7b5f8995 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
using namespace std; | |
int main(int arc, char* argv[]){ | |
string phrase; | |
string words[20]; | |
cout << "Enter in a sentence to be translated into piglatin." << endl; | |
getline (cin, phrase); | |
phrase = phrase + " "; | |
int firstIndex = 0; | |
int lastIndex = 0; | |
int wordCount = 0; | |
for(int i = 0; i < phrase.length(); i++){ | |
if(phrase.at(i) == ' '){ | |
lastIndex = i - firstIndex; | |
words[wordCount] = phrase.substr(firstIndex,lastIndex); | |
firstIndex = i + 1; | |
wordCount++; | |
} | |
} | |
for(int i = 0; i <= wordCount; i++){ | |
cout << words[i] << " "; | |
} | |
cout<< endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot I hadn't finished this program. Will pick it up as soon as I have time available. At it's current state (revision 1), it takes a line of words input and separates the words into single strings and stores them in an array. Next it should take the words and translate them into piglatin (taking the first letter and move it to the end and add ly) one by one and put them back together into a phrase to be printed.