Finding the average words per sentence

Hello everyone, I am stuck on this program and its out of my knowledge. I think I about got it but I'm at a dead end and can really use some help or advice. The challenge is I have to write a program that that reads the file's data and calculate the average number of words per sentence. It displays the sentence count right but not the words and of course and the average of words. I'm at lost. What do I need to change?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;

// Function Prototype
void dataInFile(string, string);

// Data file
fstream dataFile;

// Variables
string currentSentence;
string word;
int sentenceCount = 0;
int wordCount = 0;
double averageWords = 0;

int main()
{
	dataFile.open("C:\\Users\\Brittney\\Documents\\College Courses\\C++ 2\\Chapter 12\\Homework\\text.txt", ios::in);

	// Displays an error message if file didn't open
	if (dataFile.fail())
	{
		cout << "Error! The file did not open correctly." << endl;
		return 1;
	}

	
	getline(dataFile, currentSentence);

	while (dataFile)
	{
		// Calls function
		dataInFile(currentSentence, word);

		sentenceCount++;


		getline(dataFile, currentSentence);

	}

	// Calculates average
	averageWords = wordCount / sentenceCount;

	// Displays results
	cout << "There are " << sentenceCount << " sentences in the file." << endl;
	cout << "The file has " << wordCount << " words in it." << endl;
	cout << "The files has an average of " << averageWords << " words." << endl;

	return 0;
}

//**************************************************************
// Function Defintion for dataInFile***************************
void dataInFile(string currentSentence, string word)
{
	currentSentence = currentSentence + '.';
	string extraChars = " .,'""?;:!";
	

	dataFile >> word;
	if (word.length() > 0)
	{
		wordCount++;
	}

	return;

}
How does your input file look like?
How do you determine the end of sentence. Is it the '.' or '\n'?
My input file is this.

No one is unaware of the name of that famous English shipowner, Cunard.
In 1840 this shrewd industrialist founded a postal service between Liverpool and Halifax, featuring three wooden ships with 400-horsepower paddle wheels and a burden of 1,162 metric tons.
Eight years later, the company's assets were increased by four 650-horsepower ships at 1,820 metric tons, and in two more years, by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been renewed, successively added to its assets the Arabia, the Persia, the China, the Scotia, the Java, and the Russia, all ships of top speed and, after the Great Eastern, the biggest ever to plow the seas.
So in 1867 this company owned twelve ships, eight with paddle wheels and four with propellers.
If I give these highly condensed details, it is so everyone can fully understand the importance of this maritime transportation company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with more ability, no business dealings have been crowned with greater success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings without so much as a voyage canceled, a delay recorded, a man, a craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers still choose the Cunard line in preference to all others, as can be seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by this accident involving one of its finest steamers.


It determines I'm at the end of of a sentence when its a '.'

When I run the program, it looks like this:
I would read the file sentence by sentence using getline. The I would create a function that count the words of a sentence.
Here is a demo, maybe you can adjust it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>

using namespace std;

int WordsPerSentence (const string& sentence);

int main ()
{
  int wordCount = 0, sentenceCount = 0;

  fstream dataFile ("C:\\Users\\Brittney\\Documents\\College Courses\\C++ 2\\Chapter 12\\Homework\\text.txt", ios::in);
  
  if (dataFile.fail ())
  {
    cout << "Error! The file did not open correctly." << endl;
    return 1;
  }

  string line;
  const char EOL = '.';
  
  while (getline (dataFile, line, EOL))
  {
    sentenceCount++;
    wordCount += WordsPerSentence (line);
  }
  cout << "There are " << sentenceCount << " sentences in the file." << endl;
  cout << "The file has " << wordCount << " words in it." << endl;
  double averageWords = double (wordCount) / double (sentenceCount);
  cout << "The files has an average of " << averageWords << " words." << endl; 

  system ("pause");
  return 0;
}

int WordsPerSentence (const string& sentence)
{
  int count = 0;
  istringstream iss (sentence);
  string word;

  while (iss >> word)
  {
    count++;
  }

  return count;
}


OUTPUT:
1
2
3
4
There are 11 sentences in the file.
The file has 261 words in it.
The files has an average of 23.7273 words.
Press any key to continue . . .
Whoa thanks your a life saver! :) Its working now. I'm going to study up on this code. Thank you so much for your help.
In 1853 the Cunard Co., whose mail-carrying charter
Illustrates the problem with just counting periods, you've got to watch out for those
Topic archived. No new replies allowed.