I am trying to complete this program. It is excuting the second part of it, Which every 5th word needs to be replaced with an underline. But I need to print out the text with out the underlines first. then have it replaced with underlines. Also, the user has to enter the name of the file "spartan.txt" then it will produce orginal the file, and then it would reproduce it with the underlined section. I am not asking for the answer, JUST some guidance on what may have gone wrong. Thank you.
EXAMPLE on how it should show:
"On the banks of the Red Cedar, There's a school that's known to all; Its specialty is winning, And those Spartans play good ball; Spartan teams are never beaten, All through the game they fight; Fight for the only colors: Green and White."
"On the banks of the ______ Cedar, There's a school ______ known to all; Its ________ is winning, And those ______ play good ball; Spartan ______ are never beaten, ...."
Only the underlined part is coming out.
#include <iostream> // include standard I/O library
#include <fstream> // include standard file library
#include <iomanip> // include IO manipulators
#include <string> // include C++ string class
#include <cctype> //
using namespace std; // access standard namespace
int main ()
{
ifstream Input;
string fileName;
// variables
char name;
char last = ' ';
int blank = 1;
// book operators
bool is5blank = false;
bool print = false;
// constants
const string UNDERLINE = " ________";
cout << "Please enter the file name with .txt at the end" << endl;
cin >> fileName;
cout << "\n==================" << endl;
cout << "Cloze Version of Text" << endl;
cout << "==================" << endl << endl;
Input.open(fileName.c_str());
while (!Input)
{
cout << "Please re-enter the file name" << endl;
cin >> fileName;
cout << endl;
Input.open(fileName.c_str());
}
Input.clear(); // reset read pointer to beginning of file
Input.seekg(0L, ios::beg);
cout << endl << endl;
while ((name = Input.get()) != EOF)
{
if (isalpha(name))
{
if(blank == 0)
{
if(print == false)
{
cout << UNDERLINE;
print = true;
}
}
else
cout << name;
}
else
{
if(isalpha(last))
blank++;
if(blank == 5)
{
blank = 0;
print = false;
}
cout << name;
}
last = name;
}
Input.close();
return 0;
}