My program involves taking a list of names out of a list and displaying them onto the console. A text file located at
C:\FinalData.txt
The problem I'm having with one of my functions is that when it runs into a line with out of order data, it crashes. I've tried a few tricks to get it to take in the data past that line, but so far the best I've been able to do is get to quit when it runs into an error. I tried to increase my counting integer "i" when it runs into the error and tried to get it to go to the next line, but my method isn't working. How can I alter my code below so that when it runs into erronious or out of order data, it will move onto the next line.
The problem line is number 13.
Here is the list of names:
000001 Moshiur Ahmed I CA 90805 40 12.50
000002 Tasmia Amaat J CA 90706 35 25.60
000003 Victor Barboza K CA 90706 42 30.00
000004 Carlos Detorres I CA 90804 50 20.45
000005 Tyree Ek O CA 90755 60 15.60
000006 Amine El-Maziati M CA 90815 20 9.75
000007 Loubna El-Maziati M CA 90815 25 10.50
000008 Theresa Eyssallenne L CA 90715 40 20.00
000009 Craig Griffith I CA 90804 40 45.00
000010 Rodney Hallett H CA 90808 43 25.25
000011 Andrew Hegstrom P CA 90808 45 13.50
000012 Corey James D CA 90815 40 20.00
000013 Farsio Kottab E 90013 CA 90755 40 20.00
000014 Peter Lon W CA 90755 40 60.00
000015 Joseph Lopes A CA 90808 50 100.00
000016 Arley Lozada O CA 90280 50 30.40
000017 Ana Moreno W CA 90805 55 14.50
000018 Chris Myers Q CA 90802 57 30.00
000019 Thanakom Paiboolsilp U CA 90805 56 45.75
000020 Leonardo Priego P CA 90703 77 23.00
__________________________________________________ __
Here is my code:
Code:#include <iostream> #include <string> #include <fstream> #include <conio.h> using namespace std; void main() { string sEmployeeID[10000] = {""}; string sFirstName[300] = {""}; string sLastName[300] = {""}; string sMiddleInitial[100] = {""}; string sState[100] = {""}; int iZipCode[10000] = {0}; int iHours[100] = {0}; double dRate[1000] = {0.0}; int i = int(); ifstream finalData; finalData.open("c:\\FinalData.txt"); while(!finalData.eof()) { finalData >> sEmployeeID[i] >> sFirstName[i] >> sLastName[i] >> sMiddleInitial[i] >> sState[i] >> iZipCode[i] >> iHours[i] >> dRate[i]; if(finalData.fail()) { while(!finalData.eof()) { i++; finalData >> sEmployeeID[i] >> sFirstName[i] >> sLastName[i] >> sMiddleInitial[i] >> sState[i] >> iZipCode[i] >> iHours[i] >> dRate[i]; } } cout << sEmployeeID[i] << " " << sFirstName[i] << " " << sLastName[i] << " " << sMiddleInitial[i] << " " << sState[i] << " " << iZipCode[i] << " " << iHours[i] << " " << dRate[i] << " " << endl; i++; } }