Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// ??? This program should pause at the 24th line and wait for key punch to stri

ID: 3648734 • Letter: #

Question


// ??? This program should pause at the 24th line and wait for key punch to strike a key then read the next 24 line and pause again.
//My program does not do it. How can it get the program to pause
// Please help fix have to turn in tomorrow before midnight.



#include <iostream>
#include <fstream>


using namespace std;


int main ()
{

fstream dataFile;
char line [80];
dataFile.open ("filenames.txt", ios:: in);


if(dataFile.fail())

{
cout << "Error in file opening" << endl;
}
else
{
int counter = 0;

while (!dataFile.eof())

if (counter > 25)
{

dataFile.getline(line, 81, ' ');

cout << line << endl;
counter++;
}
}

system("pause");

return 0;

}















Explanation / Answer


#include <iostream>
#include <fstream>
#include<conio.h>


using namespace std;


int main ()
{

fstream dataFile;
char line [80];
dataFile.open ("filenames.txt", ios:: in);


if(dataFile.fail())

{
cout << "Error in file opening" << endl;
}
else
{
int counter = 0;

while (!dataFile.eof())

if (counter < 25)
{

dataFile.getline(line, 81, ' ');

cout << line << endl;
counter++;
}

getch(); //to pause

}



return 0;

}