Question: In my C++ program, I am trying to run a .txt file called incomelvlOR: 0-99%;13.8;118786 100-199%;20.6;177335 200-399%;28.7;246581 400%;36.8;316233 (the percentages would be char arrays) This

In my C++ program, I am trying to run a .txt file called incomelvlOR:

0-99%;13.8;118786 100-199%;20.6;177335 200-399%;28.7;246581 400%;36.8;316233

(the percentages would be char arrays)

This is what my c++ code looks like

#include #include #include #include using namespace std;

//globals const int CAP = 56; bool fileOpen(ifstream &inFile); void dataAnalyze(ifstream & inFile, char maxPopnamer[CAP], int &maxPop); //void sumAnalyze(&inFile);

//main int main() { ifstream inFile; char fplData[CAP]; double fplPercent = 0; int pop = 0; char maxName[CAP]; int maxPop = 0; if (!fileOpen(inFile)) { cout << "File unable to open. Teminating." << endl; return 0; } cout <<"FPL Level;" << "%;" << "Pop. Est." << endl; while (!inFile.eof()) { inFile >> fplData >> fplPercent >> pop; cout << fplData << ";" << fplPercent << ";" << pop << endl; inFile.ignore(100, ' '); }

// dataAnalyze(inFile, maxName, maxPop); // cout << "The FPL category with the highest number of children is "; // cout << maxName << " or greater with a population of " << maxPop << "." << endl; }

//function to open file bool fileOpen(ifstream &inFile) { inFile.open("incomelvlOR.txt"); if (!inFile) { return false; } return true; }

//function to get highest pop. estimate //void dataAnalyze(ifstream & inFile, char maxPopnamer[CAP], int &maxPop){ //char fplCat[CAP]; //double fplPercent = 0.00; //int fplPop = 0; //int fplMax = 0; //inFile >> fplCat >> fplPercent >> fplPop; //fplMax = fplPop; //while (!inFile.eof()) { //if(fplMax < fplPop) { //fplMax = fplPop; //strcpy(maxPopnamer, fplCat); //} //inFile >> fplCat >> fplPercent >> fplPop; //} //} (Ignore the dataAnalze function or any data relating to it, it is commented out)

I am trying to print the entire .txt file data to the user. It ends up printing:

"200-399%; 28.7; 246581;400;0"

infinitely. My first guess is that it thinks the last line is still the character "pop" and so it doesn't move on to the next line. Any ways that I can fix this?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!