This is an oddly-structured homework. It kind looks like your teacher is planning to use this as an example to segue into OOP.
In any case, notice that you have your animal menu code twice. This is a good hint that you should put it in a function, then call that function.
You should also get your code to compile, at the very minimum, before posting questions.
Then, put your code in [
code]…[
/code] blocks.
The
useranswer
should not be a global, and it should be an
integer.
This is not correct.
80 81 82 83
|
if (cin.fail() == false)
{
cin.clear();
rewind(stdin);
|
Your loop should look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int useranswer;
bool done = false;
while (!done)
{
show_menu();
cin >> useranswer;
if (!cin || (cin < 1) || (cin > 12))
{
cin.clear();
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
cout << "complain...\n";
}
|
Now, once you have your input, you need to act on it.
1 2 3 4 5 6 7 8
|
switch (useranswer)
{
case 1: Feature_DOG(); break;
case 2: Feature_CAT(); break;
…
case 12: done = true; break;
}
}
|
Unless your instructor specifically asked for it, you do not need to #define TRUE, FALSE, MENU_anything, or whatever.
If you wish your menu to be an enumerated construct, you can do that; just make the menu function return a valid enum value:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
enum Menu_Item
{
Menu_Dog = 1,
Menu_Cat,
…,
Menu_Exit,
Menu_Last = Menu_Exit
};
Menu_Item menu()
{
…
cout << "1. ) What does the dog say?\n";
…
int userinput;
while (true)
{
cin >> userinput;
if (!cin || (userinput < 1) || (userinput > Menu_Last))
{
cin.clear();
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
cout << "complain...\n";
}
else return (Menu_Item)userinput;
}
}
|
There are
much better ways to do this, but at this point I think they would be overload for you.
Hope this helps.