473,394 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

A project problem

I'm trying to create a program that opens an input file containing a telephoning directory, prompt the user for a first and last name, search and retrieve the proper name with the number attatched, and display the name. Then prompts the user to either try a new name or end program. My code is provided below but I am stumped.., I keep getting programming errors... Oh and it's C++.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cmath>

using namespace std;

void NamePrompt(string&, string&);
void SearchName(string&, string);

int main()
{
ifstream myInfile;
myInfile.open ("input.txt");
if (!myInfile)
{
cout<< "Can't open the input file. Try a different file later."<<endl;
cout<< "Program terminated.";
return 1;
}

int process;
process = 1;

while(process==1)
{
string userChoice;
string nameMatch;
NamePrompt(userChoice);
SearchName(nameMatch);
if(!nameMatch)
{
cout<< "Name not found."<<endl;
cout<< "Would you like to search for a different name?";
cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
cin>>process;
if (process!=1)
{
cout<< "Thank you for using TeleDirect. Goodbye.";
char exit_char;
cout<< "Press any char and <enter> to exit.";
cin>>exit_char;
}
}

cout<< "The match is...,";
cout<<endl;
cout<<nameMatch;
cout<<endl<< "Hopefully this is the right match..."<<endl;
cout<< "Would you like to try a different search?"<<endl;
cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
cin>>process;
}

myInfile.close();
return 0;
}

//************************************************** *************************//
void NameMatch(string& firstName, string& lastName)
{
string firstName;
string lastName;
cout<< "Enter the person's first name: ";
cin>>firstName;
cout<< "Enter the person's last name :";
cin>>lastName;
userChoice = firstName+' '+lastName;

}

//************************************************** *************************//
void SearchName(string& nameMatch, string userChoice)

{
nameMatch= cin.getline(cin, userChoice);
}
Dec 3 '06 #1
2 1176
can any one please help me ??
Dec 4 '06 #2
sivadhas2006
142 100+
can any one please help me ??
Hi,

I think, I solved all the compilation errors.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <string>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. void NamePrompt(string&);
  11. void SearchName(string&, string);
  12.  
  13. int main()
  14. {
  15.    ifstream 
  16.       myInfile;
  17.    int 
  18.       nProcess = 0;
  19.  
  20.    myInfile.open ("input.txt");
  21.    if (!myInfile)
  22.    {
  23.       cout<< "Can't open the input file. Try a different file later."<<endl;
  24.       cout<< "Program terminated.";
  25.       return 1;
  26.    }
  27.  
  28.    nProcess = 1;
  29.  
  30.    while(nProcess == 1)
  31.    {
  32.       string 
  33.          strUserChoice,
  34.          strNameMatch;
  35.  
  36.       NamePrompt(strUserChoice);
  37.       SearchName(strNameMatch, strUserChoice);
  38.       if(strNameMatch.empty())
  39.       {
  40.          cout<< "Name not found."<<endl;
  41.          cout<< "Would you like to search for a different name?";
  42.          cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
  43.          cin>>nProcess;
  44.          if (nProcess != 1)
  45.          {
  46.             cout<< "Thank you for using TeleDirect. Goodbye.";
  47.             char exit_char;
  48.             cout<< "Press any char and <enter> to exit.";
  49.             cin>>exit_char;
  50.          }
  51.       }
  52.  
  53.       cout<< "The match is...,\n";      
  54.       cout<<strNameMatch;
  55.       cout<<endl<< "Hopefully this is the right match..."<<endl;
  56.       cout<< "Would you like to try a different search?"<<endl;
  57.       cout<< "If yes, type 1. Otherwise, input any other numerical value to end program.";
  58.       cin>>nProcess;
  59.    }
  60.  
  61.    myInfile.close();
  62.    return 0;
  63. }
  64.  
  65. //************************************************** *************************//
  66. void NamePrompt(string& a_strUserChoice)
  67. {
  68.    string 
  69.       strFirstName,
  70.       strLastName;
  71.  
  72.    cout<< "Enter the person's first name: ";
  73.    cin>>strFirstName;
  74.    cout<< "Enter the person's last name :";
  75.    cin>>strLastName;
  76.  
  77.    a_strUserChoice = strFirstName + " " + strLastName;
  78. }
  79.  
  80. //************************************************** *************************//
  81. void SearchName(string& a_strNameMatch, string a_strUserChoice)
  82. {
  83.    // a_strNameMatch = cin.getline(cin, a_strUserChoice);
  84.    // Do your logic here to search the user choice.
  85.    // and set the result.
  86.    a_strNameMatch = "Hai";
  87.  
  88. }
  89.  
  90.  
Hope this may help you.

Regards,
M.Sivadhas.
Dec 4 '06 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
10
by: TokiDoki | last post by:
Hello there, I have been programming python for a little while, now. But as I am beginning to do more complex stuff, I am running into small organization problems. It is possible that what I...
3
by: David N | last post by:
I got a solution that contains about 30 projects, three of which cannot be open. When I open the project, I always receive the error message "Unable to get the project file from the Web Server" ...
7
by: George Copeland | last post by:
This is a request for assistance analyzing a problem we are experiencing in our VB6 development environment. All our code is developed in VB6, and our persistance layer is SQL Server. We are...
5
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.