
October 25th, 2012, 01:19 PM
|
|
Registered User
|
|
Join Date: Oct 2012
Posts: 1
Time spent in forums: 9 m 48 sec
Reputation Power: 0
|
|
|
General - Counting words, syllables, and sentences.
my goal is to build a program the counts the words, the syllables, and the sentences of an input.txt file, but for some reason, my code keeps failing.
keep in mind, I am very new to C++.
thanks for the help, in advance!
----------------------------------------------
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main ()
{
int wordCount, syllableCount, sentenceCount,
syllableTotal, sentenceTotal, wordTotal;
string phrase;
double index;
int x;
int i;
int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;
int yCount = 0;
syllableCount = 0;
sentenceCount = 0;
wordCount = 0;
index = 206.835 - 84.6 * syllableCount/wordCount
- 1.105 * wordCount/sentenceCount;
cin >> phrase;
wordCount = phrase.size();
while (cin >> phrase)
{
if (phrase == "\0" || phrase == ".")
{
wordCount = phrase.at("\0" || ".");
wordTotal = wordTotal + wordCount;
}
}
while (cin >> phrase)
{
char character;
for (i=0; i < x; i++);
{
if (character == 'a' || character == 'A')
aCount++;
}
for (i=0; i < x; i++);
{
if (character == 'e' || character == 'E')
aCount++;
}
for (i=0; i < x; i++);
{
if (character == 'i' || character == 'I')
aCount++;
}
for (i=0; i < x; i++);
{
if (character == 'o' || character == 'O')
aCount++;
}
for (i=0; i < x; i++);
{
if (character == 'u' || character == 'U')
aCount++;
}
for (i=0; i < x; i++);
{
if (character == 'y' || character == 'Y')
aCount++;
}
syllableTotal =
syllableTotal+(aCount+eCount+iCount+oCount+uCount+ yCount);
}
while (cin >> phrase)
{
if (phrase == "." || phrase == "\n")
sentenceCount = phrase.at("." || "\n");
sentenceTotal = sentenceTotal + sentenceCount;
}
cout << "Words: " << wordTotal << "\n" << "Syllables: " << syllableTotal <<
"\n" << "Sentences: " << sentenceTotal << "\n" << "Legibility Index: "
<< index << endl;
return 0;
}
|