So I am trying to make a banking system that gives you choices on what you want. The problem is I want to enter in option 2 and look for existing accounts through a text document,but don't exactly know how to do it. For example, if I enter in an existing account named Jason it will say "Found account for Jason".
Lines 59-60: You're using name for two different things.
1) The name you want to search for.
2) The name you read from the file. This will overlay the name you entered on line 59.
Lines 60-63: These lines will simply display every name in the file.
Perhaps something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
bool Exist (char answer)
{ string name_to_search;
string name_from_file;
if (answer == '2')
{ ifstream infile;
infile.open ("Accounts.txt");
cout << "Enter in your account:";
cin.ignore();
getline(cin, name_to_search);
while (infile >> name_from_file)
{ if (name_from_file == name_to_search)
{ cout << name_to_search << endl;
returntrue;
}
}
returnfalse; // name_to_search not found
}
}
Okay it's starting to make sense now, but when I put in an existing account it doesn't acknowledge it. Does it work as intended on your end? I don't think the if statement is going through.