Can anyone help me with a phonebook code

The program compiles fine, but when I run it it doesn't print out the number from the .dat Can anyone help me?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  #include <iostream>
#include <istream>
#include <fstream>
#include <iomanip>
#include <string>

using namespace std;

void FindName(string, string, string);
void PhoneNumber(string);

int main()
{
string firstName; // First Name
string lastName; // Last Name
string number; // Phone Number
string searchName; // First and Last Name Input


ifstream inFile;
inFile.open("phoneDirectory.dat"); // Opens input file

if ( !inFile )
{
cout << "Can't open input file." << endl;

}

cout << "Input the first and last name to lookup: ";
cin >> firstName >> lastName;
searchName = firstName + " " + lastName;
cout << searchName << "'s number is: " << number << endl; // Outputs phone number
cout << "Would you like to lookup another number?" // Asks user if they want to search for another number
<< "Enter y for yes or n for no; " << endl;

cin.get();

while (cin.get() == 'y') // If user wants to do another search
{

cout << "Input the first and last name to lookup: "; // Output Line
cin >> firstName >> lastName; // Input Line
searchName = firstName + " " + lastName; // Initialize variable
cout << searchName << "'s number is: " << number << endl;
cout << "Would you like to lookup another number?"
<< "Enter y for yes or n for no; " << endl;
cin.get();
}

inFile.close();
return 0;
}


void findName(string, string, string)
{
ifstream inFile;
string searchName;

inFile.open("phoneDirectory.dat");

while (inFile.good())
{
string lastName, firstName, number;
inFile >> firstName >> lastName >> number;
searchName = firstName + " " + lastName;
}
while (inFile.bad()) // If name is not in the directory
{
cout << "Name is not in directory. Please try again." << endl;
}
}

void findNumber (string)
{
ifstream inFile;

string number;

inFile.open("phoneDirectory.dat");

}
cout << searchName << "'s number is: " << number << endl; // Outputs phone number

uhmm, because you didn't read it from the file ?
Topic archived. No new replies allowed.