Two Plus Two Older Archives  

Go Back   Two Plus Two Older Archives > General Gambling > Computer Technical Help
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 12-08-2005, 12:34 AM
mscags mscags is offline
Senior Member
 
Join Date: Mar 2005
Location: Between Two Hot Twins
Posts: 713
Default Last C++ Question for a while

I've got my program pretty much completed except for the search algorithm. I need to let the user imput a name or partial name and search for it. I also need to let the user repeat this if they want. I'm pretty sure that means I need to make the search a function that way it is easily repeated. ANyway, I have no idea how to let the user search for a name or partial name. If anyone has any ideas please let me know. Also if you see anything wrong please tell me.

//This program will let the user imput names and phone numbers and will then let

//the user search for names and will display the reults. The user will then be able

//to repeat this if they desire.

#include <iostream>

#include <string>

using namespace std;

int main()

{

char Entries = 0;

char response[13];

char Numbers = 0;

char Search;

cout << "How many entries do you have? ";

cin.getline(response,256);

Entries = atoi(response);

string *PtrNames = new string[Entries];

string *PtrNumbers = new string[Entries];

for ( int row=0; row<Entries; row++)

{

cout << "Enter name #" << row+1 << " ";

cin.getline(response,13);

PtrNames[row] = response;

}

cout << "The " << Entries << " names that you entered are " << endl;

for (int row = 0; row<Entries; row++)

{

cout << PtrNames[row] << endl;

}

for ( int row=0; row<Entries; row++)

{

cout << "Enter Phone Number #" << row+1 << " ";

cin.getline(response,13);

PtrNumbers[row] = response;

}

for (int row =0; row<Entries; row ++)
{
for (int i=0; i<1; i++)
{
if (PtrNumbers[row][i] < '0' || PtrNumbers[row][i] >'9')
{
cout << "Phone number #"<< row+1<< " is invalid\n";
cout << "Please restart this program\n";
}
else
if
(PtrNumbers[row][4] != '-' && PtrNumbers[row][7] != '-')
{
cout << "Phone number #"<<row+1<< " is invalid\n";
}

}

}

cout << "The " << Entries << " phone numbers that you entered are " << endl;

for (int row = 0; row<Entries; row++)

{
cout << PtrNumbers[row] << endl;
}

cout << "What name would you like to search for?\n";
cin >> Search; //I have no idea where to go from here

int SeeResults;
cin >> SeeResults;

return 0;

}
Reply With Quote
  #2  
Old 12-08-2005, 01:47 AM
rt1 rt1 is offline
Member
 
Join Date: Jun 2004
Location: irc
Posts: 33
Default Re: Last C++ Question for a while

loop thru array (for loop),

if input name matches that name stored in the array, we have a winner...

ps, your validation of the phone number sucks...
Reply With Quote
  #3  
Old 12-08-2005, 04:04 AM
mscags mscags is offline
Senior Member
 
Join Date: Mar 2005
Location: Between Two Hot Twins
Posts: 713
Default Re: Last C++ Question for a while

[ QUOTE ]
if input name matches that name stored in the array, we have a winner...

[/ QUOTE ]
will that check for partial matches though?

[ QUOTE ]

ps, your validation of the phone number sucks...

[/ QUOTE ]

Any suggestions?
Reply With Quote
  #4  
Old 12-08-2005, 07:39 AM
pokergrader pokergrader is offline
Senior Member
 
Join Date: Apr 2005
Posts: 210
Default Re: Last C++ Question for a while

[ QUOTE ]
[ QUOTE ]
if input name matches that name stored in the array, we have a winner...

[/ QUOTE ]
will that check for partial matches though?


[/ QUOTE ]

Once you clearly define the meaning of "partial matches" for yourself, you have enough understanding of loops to write the code.
Reply With Quote
  #5  
Old 12-09-2005, 02:18 AM
mason55 mason55 is offline
Senior Member
 
Join Date: Sep 2004
Location: All Sin Begins With Emotion
Posts: 801
Default Re: Last C++ Question for a while

http://www.cppreference.com/cppstring/find.html
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.