I have a function for deleting data from a text file.
I'm having problems when valid input is entered:
- if I enter bad input, it only executes the
else
part, as expected - if I enter valid input, it executes both the
if
and theelse
part.
Here is my code:
void Member::processTransaction()
{
fstream f;
f.open("Member.txt",ios::in|ios::out);
int x = 0, y = 0, z = 0;
while (!f.eof())
{
f >> idList[x] >> nameList[y];
if (id == idList[x])
{
cout << idList[x] << "\t" << nameList[x] << endl;
cout << "Do you want to delete the entry (Y/N) : " << endl;
char deleteEntry = getche();
if(deleteEntry=='Y'||deleteEntry=='y')
deleteInformation();
f.close();
}
else
{
cout << "No Matches Found!";
}
}
}
in the output. If I enter True
, it executes and displays "No Matches Found".
If I enter false
, it only displays "No Matches Found" and its fine.