I have a file with first and last names and phone numbers. Now, I need to writte a program that gets a name from a user, and if the name is in the file, display the corresponding number, but if the name is not in the file, the program writes a message saying that the name is not in the file. Also, the program needs to repeat the process until the user indicates that they would like to stop. Here is my code/psudocode...
Would this be valid?? if (FirstName && LastName=="phonedir.dat")Code:#include <iostream> using namespace std; void GetFirstName and GetLastName( string) // Function prototypes void Printphonenumber (int ) void PrintQuestion (char) int main() { string FirstName; // The outside temperature string LastName; int PhoneNumber char question; GetName(FirstName & LastName); // Function call PrintPhoneNumber(PhoneNumber; PrintQuestion(Question); // Function call // Declare and open input file ifstream inData; // Input file of readings inData.open("phonedir.dat"); if ( !inData ) // Did input file open correctly? { // no cout << "Can't open input file." << endl; return 1; // Terminate program }return 0; } //****************************************************************** void GetFirstName and GetLastName ( string FirstName and LastName ) // Reference parameter // This function prompts for a first name and last name to be entered { cout << "Enter first name" << endl; cin >> FirstName; cout << "Enter Last name " << endl; cin >> LastName; } //****************************************************************** void Printphonenumber( string phonenumber ) // Value parameter // This Function outputs the corresponding number or indicates that the name // is not in the directory. If the first and last name are found in the file, then output corresponding number. else cout << "The name could not be found in the directory //******************************************************************* void (PrintQuestion) (char) //This function prints a question asking the user to find another number. //If no, terminate program. cout << "Do you want to lookup another number? (Enter Y or N)" << cin >> char; If (char == 'Y') return(); If (char == 'N') return 1; //Terminate Program
cout << phonenumber;
else
cout << "The name is not in the file";



LinkBack URL
About LinkBacks


