hi guys,
I have another noob question, I was wondering if anyone can help me with it.
the home work assignment I have is
"In this assignment we are going to write a phone directory program. The user is asked to input a name and the program looks up the address and number. The actual phone directory is a file that I’ve posted on the Web site, phoneDir. Download it.
Examine the file to see the format. Here is a part of the file:
gomez, thomas
954-182-3819
3829 Broward Blvd.
hanrity, john
954-182-3812
982 Hillcrest Rd.
michaels, marilyn
954-329-3451
16 Pine View Rd
Your program will request a name, last name first.
The program terminates when the user inputs a blank line.
Please don’t use absolute paths for your phoneDir file, as it is more difficult for your instructor to test.
so far my code is
#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
int count = 0;
string n,name,phnum,address;
ifstream out;
out.open("phoneDir.txt");
cout<<"Name please: <last name, first name> ";
getline(cin, n);
cout<<endl;
getline(out, name);
do {
if(n== name){
cout << name << endl;
getline(out,phnum);
getline(out,address);
cout << phnum <<endl<<address<<endl;
out.close();
}
}while(out>>n);
system("pause");
}
when entering the first name in the list, it works great, but it does not work on any other name.
anyone have any suggestions on how I can make this work please?
Thank you
Rusty