Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
/*
This program allows users to search through an array of string objects
In this instance they can search through an array of names and phone numbers
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
const int SIZE = 10;
string namesAndNumbers[SIZE] = {
"Renee Javens, 678-1223", "Joe Looney, 586-0097",
"Geri Palmer, 223-8787", "Lynn Presnell, 887-1212",
"Bill Wolfe, 223-8878", "Sam Wiggins, 486-0998",
"Bob Kain, 586-8712", "Tim Haynes, 586-7676",
"John Johnson, 223-9037", "Jean James, 678-4939",};
//greet the user, ask them for text to search wtih
string search;
cout << "Please type a name or partial name: ";
cin >> search;
for (int count = 0; count < SIZE; count++)
{
if (search.compare(namesAndNumbers[count]))
cout << namesAndNumbers[count];
}
system("pause");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment