diff --git a/assignmentOne/wordcounter b/assignmentOne/wordcounter index 5696913..adf7540 100755 Binary files a/assignmentOne/wordcounter and b/assignmentOne/wordcounter differ diff --git a/assignmentOne/wordcounter.cpp b/assignmentOne/wordcounter.cpp index f47419c..424772b 100644 --- a/assignmentOne/wordcounter.cpp +++ b/assignmentOne/wordcounter.cpp @@ -15,20 +15,51 @@ Dependencies: ??? #include #include #include -#include -#include -#include -#include using namespace std; // function prototypes +// NONE // class definitions +// NONE // main program int main(int argc, char **argv) { + int numSentences = 0; + int numSpaces = 0; + string tempString; + // ask user for number of sentences + cout << "How many sentences would you like to enter?" << '\n'; + cin >> numSentences; + cout << endl; + // for loop for each sentence, count the words by counting the number of spaces, print results + for (int sentenceIterator = 0; sentenceIterator < numSentences; sentenceIterator++) + { + // ask user for sentence text + cout << "Enter text for sentence " << sentenceIterator + 1 << ": " << endl; + // ignore whitespace, put ALL whitespace into cin. + cin.ignore(); + // get the input from user, dump into tempString + getline(cin, tempString); + // count number of spaces + for(int characterIterator = 0; characterIterator < tempString.size(); characterIterator++) + { + // iterate through string, count if there is space. + if(tempString[characterIterator] == ' ') + { + // count space + numSpaces = numSpaces + 1; + } + } + // add an extra 'word' because of the end. + numSpaces = numSpaces + 1; + // print out to the user + cout << "Sentence " << sentenceIterator + 1 << " has " << numSpaces << " words." << endl; + // reset word counter + numSpaces = 0; + } // return 0 return 0; }