This is what my program looks like and it still only prints out the first name in the files number.
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
char chr;
int main()
{
string first;
string last;
string number;
string firstfile;
string lastfile;
string numberfile;
char cont;
cont='Y'||'y';
ifstream infile;
infile.open("names and numbers.dat"); //opening the file
while(infile>>firstfile>>lastfile>>numberfile)
{
cout<<"Enter a first and last name."<<endl; //Asking user for the input
cin>>first>>last;
//input the data
if(first==firstfile && last==lastfile) //if the entered information matches the information in the file
cout<<firstfile<<" "<<lastfile<<"'s number is "<<numberfile<<endl; //this is printed
elseif(!(first==firstfile && last==lastfile))
cout<<"Sorry that is not in our database."<<endl; //if the information doesn't match this is printed
cout<<"Would you like to search for another name? Y or N"<<endl; //user is asked if they would like to continue
cin>>cont;
if (!cont=='y'||'Y')
return 0;
}
infile.close();
//close file
cin>>chr;
return 0;
}