Question: Tony Gaddis Starting Out With C++ Control Structures Through Objects Chapter 10 Programming Challenge 18 Phone Number List I have the program mostly completetd below

Tony Gaddis Starting Out With C++ Control Structures Through Objects

Chapter 10 Programming Challenge 18

Phone Number List

I have the program mostly completetd below but I want to display a message stating that "No entries were found" if a search comes up empty. I am stuck on this portion of the assignment as the "No entries found" message appears when information is found in the array. Works fine when no information is found in the array.

#include #include #include #include using namespace std;

int main() {

const int SIZE = 12; const int LENGTH = 30; char contacts [SIZE][LENGTH] = { "Renee Javens, 678-1223", "Joe Looney, 586-0097", "Geri Palmer, 223-8787", "Lynn Presnell, 887-1212", "Bill Wolfe, 223-8878", "Same Wiggins, 486-0998", "Bob Kain, 586-8712", "Tim Haynes, 586-7676", "John Johnson, 2223-9037", "Jean James, 678-4939", "Ron Palmer, 486-2783" }; char search[LENGTH]; char *strPtr = nullptr; int index; char repeat;

do { cout << "Please enter a name to search for contact information. " << endl; cin.getline(search, LENGTH);

/***** Stuck here the program displays the right information when searching "Pal" but also displays the no results message. No results message displays fine when no results are found********/ for (index = 0; index < SIZE; index++) { strPtr = strstr(contacts[index], search); if (strPtr != nullptr) cout << contacts[index] << endl; }

if (strPtr == nullptr)

cout << "No information matches the search criteria. " << endl; // Ask user to repeat program cout << "Would you like to search again? Y/N? " << endl; cin >> repeat; cin.getline(search, LENGTH);

} while (repeat == 'Y' || repeat == 'y');

system("pause"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!