0

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;
}
3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by acerious
0

Bump! I'd like to know more in depth for how to do this too, preferably without the use of structure functions and it will complicate things a lot more. Can't we create a loop, find userid, check pin in that loop and return true or false based on the match?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.