Ch 11 Debug Pseudocode Wrote own file & named it CH_11_Data_LC.txt Replaced location of older file with new file location and name of file. Had to debug own coding for a new file location as I had made my input my output causing it to write over my input. Found errors in the code and fixed them. Duplicated the while loop to be outside of the while and inside. Changed <= to < on line 137 In part 2 if you change the input from double slash to single slash it will cause the program to fail. double slash is always a requirement. Changing and tampering with input and output placements causes error coding. Best way is to copy the address of the file you use by going to the files properties and copying it's address. #include #include // For the files!!!! // lol stream......good thing its not a pstream ^o^ . #include // For manipulators & formatting options using std::cin; using std::cout; using std::endl; using std::setw; using std::ios; using std::ifstream; using std::ofstream; const int EMPLOYEES = 20; const int MAX = 21; int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]); void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter); void PrintTotalsAndSummary(ofstream& out, int totalRecords); int main() { char name[EMPLOYEES][MAX]; int age[EMPLOYEES]; int record_counter(0); ifstream inFile; // Notice how this automatically opens the file ofstream outFile("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Report.txt"); inFile.open("C:\\Users\\Lloyd Crawford\\source\\repos\\cst116-ch11-debugging-19-Ruin\\CH_11_Data_LC.txt"); // double slash has to be used in all file in or out. If you use a single slach bad things happen. if (inFile.is_open()) { record_counter = ReadData(inFile, outFile, name, age); inFile.close(); if (outFile.is_open()) { WriteOutputFile(outFile, name, age, record_counter); PrintTotalsAndSummary(outFile, record_counter); outFile.close(); } else { cout << "Trouble Opening File"; cout << "\n\n\t\t ** About to EXIT NOW! ** "; } } else { cout << "Trouble Opening File"; cout << "\n\n\t\t ** About to EXIT NOW! ** "; } return 0; } int ReadData(ifstream& inFile, ofstream& outFile, char name[][MAX], int age[]) { int counter = 0; inFile >> name[counter] >> age[counter]; // Priming Read while (!inFile.eof()) { cout << setiosflags(ios::left) << setw(25) << name[counter] << resetiosflags(ios::left) << setw(4) << age[counter] << endl; counter++; inFile >> name[counter] >> age[counter]; } // next segment is for reading and priming the file. cout << setiosflags(ios::left) << setw(25) << name[counter] << resetiosflags(ios::left) << setw(4) << age[counter] << endl; counter++; inFile >> name[counter] >> age[counter]; return counter; } void WriteOutputFile(ofstream& outFile, char name[][MAX], int age[], int counter) { outFile << " Here is the Output File" << endl; for (int r = 0; r < counter; r++) // femove the = here to stop the report from adding wierd coding to your solution and your file. nasty bug. { outFile << setiosflags(ios::left) << setw(25) << name[r] << setw(4) << resetiosflags(ios::left) << age[r] << endl; } } void PrintTotalsAndSummary(ofstream& outFile, int totalRecords) { // To screen cout << "\n\n\t** Total Records: " << totalRecords << " **\n" << "\t\t The End \n"; // To file outFile << "\n\n\t** Total Records: " << totalRecords << " **\n" << "\t\t The End \n"; Felt like I learned in this lesson and once I found how to do it, it felt like it went quick. output Vincent 24 Johnny 81 Hector 45 Ranni 89 Radahn 90 DrLivesly 45 Powerwolf 10 Iggy 23 Bertrum 15 Goofy 99 ** Total Records: 10 ** The End C:\Users\Lloyd Crawford\source\repos\cst116-ch11-debugging-19-Ruin\x64\Debug\CST116-Ch11-Debugging-Crawford.exe (process 18708) exited with code 0. To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops. Press any key to close this window . . .