Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

4. Did you rethink your decision?

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago