counting words

Ask for help with your homework/assignments in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Postby iamkim » Mon Dec 08, 2003 3:45 pm

I ended up using the following code.. but I didn't come up with how to find the average word length with it so I'll probably only get 50% credit if that.

Code: Select all
/* Count Words  program
Pre: InFile contains a a string.
Post:  returns number of words and average word length of InFile  */



#include <string>
#include <fstream>
#include <iostream>
using namespace std;

main() {

  string word;
  ifstream InFile;
  int i = 0;

  InFile.open("source.txt");

  while(InFile >> word) {
    i++;
  }

  cout <<"Total Words: "<< i << '\n';
  return 0;

}


Thanks for your help everybody! :)
iamkim
 
Posts: 33
Joined: Wed Nov 05, 2003 3:01 pm
Location: ct

Previous

Return to Homeworks

Who is online

Users browsing this forum: No registered users and 1 guest