I'm working on a program driven by a menu. At the end of each menu component, the user will have the option of running that component again. If they enter an invalid entry (not a y or n) I want to go back to the main menu. I shortened my code below to just show the relevant parts. The problem I'm having is I can't get the entire program to loop through again. After the invalid entry, the user is taken back to the main screen and inputs a selection, but then the program stops it doesnt continue on with that selection.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
//function prototypes
char getSelection();
void displayThankYou();
int main()
{//Begin main function
//declare variables
string name;
char selection;
double items = 0;
char another = 'Y';
char answer = 'Y';
do
{//do while for default switch
selection = getSelection();
switch (selection)
{
case '1':
do
{//Begin do-while function to run program again
//... code goes here
cout << "Would you like to run the receipt program again? (Y/N) : ";
cin >> another;
}while(toupper(another)=='Y');
if(toupper(another)=='N')
{
displayThankYou();
return 0;
}
else if(toupper(another)!='Y'|| another != 'N')
{
selection = getSelection();
}
return 0;
break;
default:
cout << "***************************************" << endl;
cout << "***************************************" << endl;
cout << "****** T H A T W A S N O T ******" << endl;
cout << "****** A V A L I D O P T I O N ******" << endl;
cout << "***************************************" << endl;
cout << "***************************************" << endl << endl;
cout << "Would you like to return to the main menu? (Y/N): " ;
cin >> answer;
} //end switch
}while(toupper(answer)=='Y');
return 0;
}//end of main function
//*******************function definitions
char getSelection()
{
char choice;
cout << "Option Description" << endl;
cout << "---------------------------" << endl;
cout << " 1 Create a sales receipt"<< endl;
cout << " 2 Create a customer contact card" << endl;
cout << " 3 Balance a checkbook"<< endl;
cout << " 4 Create a trip mileage report"<< endl;
cout << " 0 Exit program" << endl << endl;
cout << "What is your selection?";
cin >> choice;
return choice;
cout << endl << endl << endl;
}
void displayThankYou()
{
cout << "**************************************" << endl;
cout << "**************************************" << endl;
cout << "******* T H A N K Y O U *******" << endl;
cout << "******* F O R U S I N G *******" << endl;
cout << "******* T H I S P R O G R A M *******" << endl;
cout << "**************************************" << endl;
cout << "**************************************" << endl;
}