Last active
January 27, 2016 07:17
-
-
Save NickersF/65a6a9929e746075ed8b to your computer and use it in GitHub Desktop.
General menu function:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Nick Fazzolari | |
#include <iostream> | |
using namespace std; | |
void userMenu(char menuSelection); | |
void printMenu(); | |
void baseUi(); | |
// void baseUi({params for locals in main here}); | |
int main() { | |
// My idea is to only store function calls, variables/arrays in main | |
// and class objects. | |
baseUi(); | |
return 0; | |
} | |
// this function handles the user input | |
void userMenu(char menuSelection) { | |
switch (menuSelection) { | |
case '1': | |
cout << "Menu Selection '1'" << endl; | |
break; | |
case '2': | |
cout << "Menu Selection '2'" << endl; | |
break; | |
case '3': | |
cout << "Menu Selection '3'" << endl; | |
break; | |
case 'q': | |
cout << "Shutting down..." << endl; | |
exit(0); | |
break; | |
default: | |
cout << "Invalid input."; | |
} | |
} | |
// this function prints the avilable menu options | |
void printMenu() { | |
cout << endl | |
<< "Please make a selection: " << endl | |
<< "[ 1 ] Menu selection 1: " << endl | |
<< "[ 2 ] Menu selection 2: " << endl | |
<< "[ 3 ] Menu selection 3: " << endl | |
<< "(When done enter 'q' to quit): " << endl | |
<< "Make a menu selection: "; | |
} | |
// this function gets the menu input and controls its execution | |
void baseUi() { | |
char menuSelection; | |
do { | |
printMenu(); | |
cin >> menuSelection; | |
cin.clear(); | |
cin.ignore(100, '\n'); | |
// parse user input | |
userMenu(menuSelection); | |
} while (menuSelection != '4'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment