Trying to find the longest and shortest words from a .txt file, PLEASE HELP!

I have tried a few different things, this was my start point


#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <cctype>
#include<algorithm>
using namespace std;

string chooseTextFile( );
string longest(string fileName, string longestWord() );

int main( )
{
int j=0;
string fileName;
int choice=0;
int wordCount=0;
string word[100];
string selectWords;
string selectedWords[100];
string shortestWord ("abcdefghijklmnopqrstuvwxyz");
string longestWord (" ");
int selectWordCount[100];
// use while loop to read select word file
ifstream inFile;
inFile.open( "selectwords.txt" );
while( !inFile.eof() ) {
for ( int i=0; i<100;i++){
inFile >> selectedWords[i];
}
}
inFile.close();
for ( j=0; j<100;j++){
selectedWords[j];
//cout << selectedWords[j] << endl;
}
do{
// Use function to read in user choice
fileName = chooseTextFile( );
if( fileName == "exit" ) break;

// use while loop to open file, run ispunct function, count, determine longest and shortest, determine % etc
ifstream inFile;
inFile.open( fileName );
while( !inFile.eof() ) {
inFile >> fileName;
fileName.erase(remove_if (fileName.begin (), fileName.end (), ispunct), fileName.end ());
transform(fileName.begin(), fileName.end(), fileName.begin(), tolower);
cout << fileName << endl;
//figure out longest and shortest words
//nested if statments to iterate through selectedWords and count

/*for (int i = 0; i< 100; i++){
if ( word[i].size () > longestWord.size ()){
longestWord= word[i];
}
}
cout << longestWord << endl;*/
wordCount++;
}
inFile.close();

// use struct to output results
}while(true);
system("pause");
return 0;
}


// User Choice function
string chooseTextFile( ){
string fileName;
string fileNames[] = {"A Modest Proposal.txt", "Apology.txt",
"The Adventures of Tom Sawyer.txt", "The Call of the Wild.txt", "exit" };
int choice = -1;
cout << "Please select a file to read: " << endl;
cout << "1. A Modest Proposal" << endl;
cout << "2. Apology" << endl;
cout << "3. The Adventures of Tom Sawyer" << endl;
cout << "4. The Call of the Wild" << endl;
cout << "5. Exit the program" << endl;
cout << "Choose a file by its number (1-4 or 5 to exit): ";
cin >> choice;
while( choice < 1 || choice > 5 || cin.fail() ) {
cin.clear();
cin.ignore(1000, '\n');
cout << "That's not a valid choice. Please try again (1-5): ";
cin >> choice;
}
Read the first word and set it to longest and shortest. Then read the rest of the words one at a time and check if it is longer than longest or shorter than shortest and assign to longest or shortest appropriately.
Topic archived. No new replies allowed.