I need to make a program that asks the user for their name and PIN number, then have it check the accounts file and see if that user is in there. If it finds a match it will output the users account balance. I have the text file set up and the program seems to work but only with the first account in the text file. Any accounts below that are just ignored.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;
int main ()
{
bool found=false;
int PIN;
int uPIN;
string name;
string uname;
string ID;
float balance;
ifstream infile;
infile.open ("accounts.txt");
cout<< "Please enter your name: ";
cin >> uname;
cout<< "Please enter your PIN: ";
cin >> uPIN;
while(infile)
{
infile >> ID >> name >> PIN >> balance;
{
if (uname == name && uPIN == PIN)
found = true;
}
}
{
if(found == false)
cout << "DENIED" << endl;
}
{
if (found == true)
cout << "Approved" << endl;
}
infile.close();
system("pause");
return 0;
}