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;

   infile >> ID >> name >> PIN >> balance;
       if (uname == name && uPIN == PIN)
           found = true;

       if(found == false)
           cout << "DENIED" << endl;
       if (found == true)
           cout << "Approved" << endl;

   return 0;
6 Years
Discussion Span
Last Post by acerious

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.