Code:
#include<iomanip>
#include<string>
#include<cctype>
#include<iostream>
using namespace std;
string format(string, int); //format word, first letter capital, rest lower
int findconsonants(string,int); //used to count consonants
int findpuncmarks(string, int); //used to count punctuation marks
int main()
{
string word; //not using all of these, some are left over, from trial and error
int wordcount=0;
int consonants=0;
int wordlength=0;
double avgword;
int puncmarks=0;
string longestword="";
string changedword="";
string previousword="";
cin >> word;
cout << fixed << showpoint << setprecision(3);
// cout << left << setw(50) << endl;
while (!cin.eof())
{
wordcount++; //count words
if(word.length() > longestword.length()) //find longest word
longestword= word;
word = format(word, word.length()); //call for function to reformat word
puncmarks= puncmarks+findpuncmarks(word, word.length());
consonants= consonants+findconsonants(word, word.length())-findpuncmarks(word,word.length());
wordlength= wordlength+word.length();
changedword= changedword+ word+' ';
cin >> word;
}
cout << changedword << endl; //basic output
avgword= (wordlength*1.0)/(wordcount*1.0);
cout << endl << endl;
cout << "# words: " << wordcount <<endl;
cout << "# consonants: " << consonants-1 <<endl;
cout << "ave word length: " << avgword <<endl;
cout << "# punctuation marks: " << puncmarks <<endl;
cout << "longest word: " << longestword << endl;
return 0;
}
everything else works except the output of the words in the file. obviously the way it is now it just prints the words with a space between, until the line ends. but ive tried using if else stmts and other things... i just don't know how to separate the string changedword, without seperating every word.... is this enough of the code, or would like the functions too?