Basically this Menu works however, when I enter in a string the default does catch it but then the Menu repeats the error so in essence isnt full proof. Would the way around this be to check the 1st entry by the user to see if its an integer, if so progress to the do while if not give an initial error message till they enter an integer? Or is there a wiser way around this annoying flaw? Thanks.

do { // Do While Loop that incorporates Menu and List Functions
	system("cls"); //clears previous entries & redisplays the Menu per selection
	 // Displays Menu Screen for user interaction of List
	cout << "**********Menu*************"<< endl; 
	cout << "*   1. Populate List      *"<< endl;
	cout << "*   2. Sort list          *"<< endl;
	cout << "*   3. Search List        *"<< endl;
	cout << "*   4. Display List       *"<< endl;
	cout << "*   0. Exit               *"<< endl; 
	cout << "***************************"<< endl;
	cout << "                           "<< endl;
	cout << "Please select your option  "<< endl;
        cin >> n;
	cout << "                           "<< endl;
    
		switch (n)
		{
		case 1 :
			disp.populate(); 
			cout << "List populated."<< endl;
			system("Pause");
		break;
		case 2 :
			disp.sort(); 
			system("Pause");
		break;
		case 3 :
			cout << "Please enter the value you wish to search from the List"<< endl;
			cin  >> p;
			system("Pause"); 
		break;
		case 4 :
			disp.toString(); 
			system("Pause");
		break;
		default:
			if (n !=0) 
			{
			cout << "Enter a number relating to the Options shown!!!" << endl;
			system("Pause");
			}
		break;
		} 
	}
	while (n != 0); // Exit Condition
	system("Pause");

Your loop encompasses both the menu and the selector, as:

do {
  display_menu();
  select_option();
while (!done);

So if the option is bad, the menu gets displayed again anyway.

What you'd probably like instead is something that catches itself. You can do it several ways, but another loop will probably do just fine.

do {
  display_menu();
  do {
    select_option();
  while (invalid_option);
while (!done)

Hope this helps.

commented: Thanks again mate! +1

Hey Just use the return Statement to Exit.

and in the switch statments Add the following. So the program returns a value and ends.

case 0:

return 0;

break;
commented: Thanks, appreciated! +1

Cheers guys - Duoas and Sky Diploma.

Ill attempt both suggestions!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.