title: C++ print string one word at a time, count characters, and average of characters
body: <p>how can I print a single word from a string in each line with the number of characters right next to it and the average of the characters together? I'm suppose to use a string member function to convert the object into a c string. The function <strong>countWords</strong> accepts the c string and returns an int. The function is suppose to read in each word and their lengths including the average of characters. I have done how much words are in the string except I don't know how continue the rest. </p>
  
  <p>For example: super great cannon boys</p>
  
  <p>super 5</p>
  
  <p>great 5</p>
  
  <p>cannon 6</p>
  
  <p>boys 4</p>
  
  <p>average of characters: 5 </p>
  
  <p>This is my program so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;cstring&gt;
  
  using namespace std;
  
  int countWords(char *sentence);
  
  int main()
  {
      const int size=80;
      char word[size];
      double average=0;
      cout&lt;&lt;"Enter words less than " &lt;&lt;size-1&lt;&lt;" characters."&lt;&lt;endl;
      cin.getline(word, size);
      cout &lt;&lt;"There are "&lt;&lt;countWords(word)&lt;&lt;" words in the sentence."&lt;&lt;endl;
  
      return 0;
  }
  
  int countWords(char *sentence)
  {
      int words= 1;
      while(*sentence != '\0')
      {
          if(*sentence == ' ')
              words++;
          sentence++;
      }
      return words;
  }
  </code></pre>