I have this function that is supposed to read to the end of a text file retrieve the data and store the data in some variables.
First Name-Last Name-Nationality-Guest(s)-Cost-Room #
dd dd dd 2 350 102 RIC Thing USA 2 350 104
I then use another function to try and modify the data. You can see where the variable has the data but when I'm trying to compare the data is say it is not found.
It found 104
Please enter the room number you would like to make the changes to : 104
First Name-Last Name-Nationality-Guest(s)-Room #
These two were printed so I could see what was retrieved 102 104
RIC Thing USA 2 350 104
But not finding 102.
Please enter the room number you would like to make the changes to : 102
First Name-Last Name-Nationality-Guest(s)-Room #
These two were printed so I could see what was retrieved 102 104
SORRY...NO MATCH FOUND.
Please ensure that the room number typed was was booked before it can be modified.
void HotelRoom::modifyresroom()
{
int occup;
string roomtochange;
string guestroomdb;
int newaccupancy;
double newcost;
char savinf;
string fname, lname, nationality;
string checkaddroom;
ifstream getdatafromaddroom; // creation of the ifstream object
getdatafromaddroom.open("reserveroom.out");
cout << "Please enter the room number you would like to make the changes to : ";
cin >> roomtochange;
cout << endl;
if (getdatafromaddroom.fail()) // if statement used for error
// checking
{
cout << "Could not open file" << endl; // message that will be
}
cout << "First Name" << '-' << "Last Name" << '-' << "Nationality" << '-' << "Guest(s)" << '-' << "Room #" << endl;
cout << "-------------------------------------------------------" << endl;
while (!getdatafromaddroom.eof()) {
getdatafromaddroom >> fname >> lname >> nationality >> occup >> cost >> guestroomdb;
if (getdatafromaddroom.eof()) {
break;
}
cout << guestroomdb << endl;
}
//if statement begin by error checking
if (roomtochange != guestroomdb) {
cout << "SORRY...NO MATCH FOUND." << endl;
//cout << setw(5) << fname << ' ' << setw(10) << lname << ' ' << setw(10) <<nationality << ' ' << setw(10) << occup<< ' ' << setw(9) << cost << ' ' << setw(9) << guestroomdb <<endl;
char backtomod;
cout << endl;
cout << "Please ensure that the room number typed was was booked before it can be modified." << endl;
cout << endl;
cout << "1 - Enter another room number, 2 - Back to the mail menu : ";
cin >> backtomod;
//switch block used to allow the user to reenter the room number or go back to the mail menu
switch (backtomod) {
case '1':
HotelRoom::modifyaddromm();
break;
case '2':
HotelRoom::hotelmenu();
break;
default:
cout << endl;
cout << "(--" << backtomod << "--)"
<< " wasn't a valid selection. you will now be directed to the main menu.";
system("Pause");
cout << endl;
HotelRoom::hotelmenu();
break;
}
}
else {
// if room number is found t will be printed out below
cout << setw(5) << fname << ' ' << setw(10) << lname << ' ' << setw(10) << nationality << ' ' << setw(10) << occup << ' ' << setw(9) << cost << ' ' << setw(9) << guestroomdb << endl;
}
cout << "How many person should be in the new room? : ";
cin >> newaccupancy;
newcost = newaccupancy * HotelRoom::getdailyrate();
cout << endl;
cout << "[y] to save : ";
cin >> savinf;
cout << fname << ' ' << lname << ' ' << nationality << ' ' << newaccupancy << ' ' << newcost << ' ' << guestroomdb << endl;
if (savinf == 'y' || savinf == 'Y') {
ofstream editrecord;
editrecord.open("reserveroom.out", ios::app);
editrecord << fname << ' ' << lname << ' ' << nationality << ' ' << newaccupancy << ' ' << newcost << ' ' << guestroomdb << endl;
editrecord.close();
getdatafromaddroom.close();
hotelmenu();
}
else {
cout << "The changes made weren't saved.";
system("Pause");
hotelmenu();
}
//}
}