[Solved] While loop / Thread breakpoint occurs [closed]


You are shooting past your fixed-sized arrays due to a defective EOF test. Your loop should look more like the following:

// also, don't do preceding "usageFile >> ... ;"

while (true) {
  // you should also push as many of your charge/count variable declaration
  // in here as possible ...

  // "readFile" is a poor name here, since it actually doesn't
  readFile(usageFile, lowCharge, midCharge, highCharge, lowCount,
    midCount, highCount, planType, phoneCharge);

  usageFile >> phoneNumber >> planType >> phoneCharge;

  if (usageFile.eof()) {
    break;
  }

  cout << phoneNumber << " " << planType << " " << phoneCharge << endl;
};

or

// If you can't use `break` due to your teacher's rules ...
// Note that this is worse style since it uses the hacky "firstTime" check.
bool firstTime = true;
do {
  if (!firstTime) {
    cout << phoneNumber << " " << planType << " " << phoneCharge << endl;
  }
  firstTime = false;

  readFile(usageFile, lowCharge, midCharge, highCharge, lowCount,
    midCount, highCount, planType, phoneCharge);

  usageFile >> phoneNumber >> planType >> phoneCharge;
} while (!usageFile.eof());

11

solved While loop / Thread breakpoint occurs [closed]