Hey everyone I'm very new to c++ and need some help. I'm trying to write a program that opens a text file, prints it, then prints it again with every 5th word replaced by blanks. I can get the file to open and the header for the 2nd print, but I can't get the file even print out again, or my word count to work. Any help is welcome. here's the code:
Code:#include <iostream> #include <fstream> #include <iomanip> #include <cstring> #include <cctype> using namespace std; int main () { char ch, car; char fileName [20]; bool lastWasLetter = false; bool thisLetter = false; char BLANKS [13] = " __________ "; int wordCount = 0; ifstream inFile; cout << "Give file name:" << endl; cin >> fileName; inFile.open (fileName); inFile.get (ch); while (!inFile) { inFile.clear (); cout << "File name invalid. Please re-enter the file name:" << endl; cin >> fileName; inFile.open (fileName); inFile.get (ch); } cout << "=========================================" << endl; cout << " ORIGINAL TEXT " << endl; cout << "=========================================" << endl; cout << ch; while (inFile) { inFile.get (ch); cout << ch; } inFile.seekg(0L, ios::beg); cout << "========================================" << endl; cout << " CLOZE TEST " << endl; cout << "========================================" << endl; while (inFile) { inFile.open (fileName); cin.get (ch); if (isalpha (ch)) { lastWasLetter = true; cout << ch; if (lastWasLetter = true) { cin.get (car); if (isalpha (car)) { thisLetter = true; cout << car; } else (!isalpha (car)); { wordCount++; } } } if (wordCount % 5) { cout << BLANKS; } } return (0); }