for my computer programming class, we are suppose to create a program that asks the user to enter a file name, and after the file is brought up the next step is for a cloze text to pop up. we are suppose to write the code for that every 5th word is replaced with a series of 10 underscores. I cannot seem to get the underscores to work so if anyone could help that would be awesome.
Thanks
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main ()
{
// named constants
const string UNDERLINE = "__________";
string filename;
ifstream infile;
bool notinfifthword = true;
bool prevletter = false;
bool infifthword = false;
int wordcount = 0;
char ch;
int number = 0;
int wordmax = 5;
// Ask user to enter File name
cout << "Enter File Name" << endl;
cin >> filename;
infile.open("austin.txt");
// Write the main output heading
cout << "-------------------------------------" << endl;
cout << "EchoPrinted Text" << endl;
cout << "-------------------------------------" << endl << endl;
infile.get(ch);
while (infile)
{
cout << ch;
infile.get(ch);
}
infile.clear(); // reset read pointer to very beginning of file
infile.seekg(0L, ios::beg);
cout << "--------------------------------------" << endl;
cout << "Cloze Test Version of Text" << endl;
cout << "-------------------------------------" << endl << endl;
infile.get(ch);
while (infile)
{
cout << ch;
infile.get(ch);
}
// Figure out if in new word
if(isalpha(ch)) // Current is letter
if(prevletter = false) // Previous character is not a letter
{
// New word
wordcount ++;
if(prevletter = true);
if(wordcount = 5);
} // In fifth word
cout << "__________";
wordcount = 0;
if(infifthword = true);
else
cout << ch;
{ // In middle of word
if(infifthword = false)
cout << ch;
}
if(notinfifthword = true)
cout <<ch;
infile.get(ch)
;cout << " <<< Finished Program Successfully >>> " << endl << endl;
return (0);
}
/* ========================================================================== */
/* E N D O F P R O G R A M */
/* ========================================================================== */