I am currently practice to upgrade my (novice) skills and I want to know if there any default/universal way of coding the menu choices. For example:
1. Wake up
2. Sleep
3. Sit Down
4. Take Home
Select you choice:
I thought of this:
Code:
#include <iostream>
using namespace std;
enum CHOICE {
Wake = 1,
Bath,
Toilet,
Hack,
Quit };
// Function Definition and Prototype
int DoMenu()
{
int choice;
cout << endl << endl;
cout << " ***** Menu ***** " <<endl;
cout << "(1) Wake me up when project ends" << endl;
cout << "(2) GOTO Bathroom" << endl;
cout << "(3) fflussh(toilet)" << endl;
cout << "(4) Hack the kernel" << endl;
cout << "(5) Quit" << endl;
cin >> choice;
return choice;
}
int main()
{
int choice;
bool fQuit = false;
while (!fQuit)
{
choice = DoMenu();
if ( choice < Wake || choice > Quit )
{
cout << "Wrong pal";
cout << endl << endl;
continue;
}
switch(choice)
{
case Wake:
cout << "Drinsane!!! " << endl;
break;
case Bath:
cout << "Please wait while bathing ... " << endl;
cout << "You smell sehr gut" << endl;
break;
case Toilet:
break;
case Hack:
break;
case Quit:
fQuit = true;
cout << "\nExiting .... " << endl << endl;
break;
default:
fQuit = true;
cout << "\nExiting .... " << endl << endl;
break;
}
}
system("PAUSE");
return 0;
}
ButI think that the above source code is strange a bit. Is there any particular style that you, experienced programmers use ?