//*********************************************************************
// FUNCTION: ReadRecordsFromFile
// DESCRIPTION: reads records from the file Residents.txt
// INPUT:
// Parameters: none
// File: RESIDENTS.TXT
// OUTPUT:
// Return Val: boolean
// Parameters: none
// File: none
// CALLS TO: ConverStringToNumber
//**********************************************************************
bool ReadRecordsFromFile (int totalRecords, RecordType ResidentRecord)
{
string fileName;
char userChoice;
bool check = false;
ifstream recordFile (fileName);
cout << "Please enter file name: ";
cin >> fileName;
totalRecords = 0;
while (!recordFile)
{
cout << "This file you have chosen does not exist." << endl << endl;
// if file does not exist
while (!check)
{
check = true;
// ask user for another choice
cout << "Would you like to choose another (Y/N)? ";
cin >> userChoice;
userChoice = (toupper (userChoice));
if (userChoice == 'Y')
{
recordFile.clear ();
// ask user for file name
cout << "Please enter file name: ";
cin >> fileName;
// open new file
recordFile.open (fileName);
}
elseif (userChoice == 'N')
{
returnfalse;
}
else
{
check = false;
cout << "Invalid Entry! Please try again." << endl << endl;
}
}
}
if (recordFile)
{
cout << "file found" << endl;
}
// loop while file has the records
while (recordFile.good () && recordFile.peek () != EOF)
{
recordFile >> ResidentRecord.socialSecurityNumber;
recordFile >> ResidentRecord.lastName;
recordFile >> ResidentRecord.phoneNumber;
recordFile >> (int&) ResidentRecord.typePhone;
totalRecords++;
// increment total records
RecordNode* pcur = new RecordNode ();
// set next an dprevious pointers
pcur -> ResidentRecord = ResidentRecord;
pcur -> Next = NULL;
pcur -> Prev = RecordsTail;
if (RecordsTail == NULL)
{
RecordsHead = RecordsTail = pcur;
}
else
{
RecordsTail -> Next = pcur;
RecordsTail = pcur;
}
}
//close file
recordFile.close ();
cin.clear ();
}// end ReadRecordsFromFile
I can't figure out what is going wrong right now...
I am trying to enter a file name, if the file name isn't found I want it to display the error saying file cannot be found, then ask if they want to choose another file. If they choose to enter another file, i need it to ask again for the file name....and continue that until they enter a valid file name. If they choose not to, i need it return false so that i can go on to the next step. Currently i am getting multiple error messages...