Void list? C++

I am not asking anybody to help write the code but for the project i am trying to do i have a simple animal menu, where the user enters in a number and it displays what the animla would say, but my the problem i am stuck on is right at where the animal says part. cause my teacher is using Void Feature for each. My question is that do i have to number or declare each to a number certsin set of number to let it then display. if so how do i go from doing this.

#include "pch.h"
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
float useranswer;
#define TRUE 1
#define FALSE 0
#define MENU_UNSET -1 // no menu option selected
#define MENU_LOWEST 1 // indicates the value of the lowest menu code
#define MENU_DOG 1 // DOG option...
#define MENU_CAT 2 // CAT option...
#define MENU_BIRD 3 // BIRD option...
#define MENU_MOUSE 4 // MOUSE option...
#define MENU_COW 5 // COW option...
#define MENU_FROG 6 // FROG option...
#define MENU_ELEPHANT 7 // ELEPHANT option...
#define MENU_DUCK 8 // DUCK option...
#define MENU_FISH 9 // FISH option...
#define MENU_SEAL 10 // SEAL option...
#define MENU_FOX 11 // FOX option!!!
#define MENU_EXIT 12 // indicates the user wants to exit
#define MENU_HIGHEST 12 // indicates the value of the highest menu code
// Provide function prototypes.
void Feature_DOG();
void Feature_CAT();
void Feature_BIRD();
void Feature_MOUSE();
void Feature_COW();
void Feature_FROG();
void Feature_ELEPHANT();
void Feature_DUCK();
void Feature_FISH();
void Feature_SEAL();
void Feature_FOX();

int main() {
// YOUR MENU IMPLEMENTATION GOES HERE
std::cout << "+------------------------------------+" << endl;// menu header
std::cout << "|------------ ANIMAL MENU -----------|" << endl;// menu header
std::cout << "+------------------------------------+" << endl;// menu header
cout << "1. ) What does the dog say?" << endl;
cout << "2. ) What does the cat say?" << endl;
cout << "3. ) What does the bird say?" << endl;
cout << "4. ) What does the mouse say?" << endl;
cout << "5. ) What does the cow say?" << endl;
cout << "6. ) What does the frog say?" << endl;
cout << "7. ) What does the elephant say?" << endl;
cout << "8. ) What does the duck say?" << endl;
cout << "9. ) What does the fish say?" << endl;
cout << "10.) What does the seal say?" << endl;
cout << "11.) What does the fox say?" << endl;
cout << "12.) Exit Program" << endl;
cout << "Which menu item would you like to exacute: ";
cin >> useranswer;

while (true)
{
cout << endl;
std::cout << "+------------------------------------+" << endl;// menu header
std::cout << "|------------ ANIMAL MENU -----------|" << endl;// menu header
std::cout << "+------------------------------------+" << endl;// menu header
cout << "1. ) What does the dog say?" << endl;
cout << "2. ) What does the cat say?" << endl;
cout << "3. ) What does the bird say?" << endl;
cout << "4. ) What does the mouse say?" << endl;
cout << "5. ) What does the cow say?" << endl;
cout << "6. ) What does the frog say?" << endl;
cout << "7. ) What does the elephant say?" << endl;
cout << "8. ) What does the duck say?" << endl;
cout << "9. ) What does the fish say?" << endl;
cout << "10.) What does the seal say?" << endl;
cout << "11.) What does the fox say?" << endl;
cout << "12.) Exit Program" << endl;
cout << "Which menu item would you like to exacute: ";
cin >> useranswer;

if (cin.fail() == false)
{
cin.clear();
rewind(stdin);
cout << "That doesn't appear to be a valid option. Please try again..." << endl;
cout << endl << "Which menu item would you like to exacute: ";
cin >> useranswer;
}
}
// It's over!
return 0; // return to OS
}
void Feature_DOG() {
cout << "Dog goes \'WOOF\'." << endl << endl;
}
void Feature_CAT() {
cout << "Cat goes \'MEOW\'." << endl << endl;
}
void Feature_BIRD() {
cout << "Bird goes \'TWEET\'." << endl << endl;
}
void Feature_MOUSE() {
cout << "And the mouse goes \'SQUEEK\'." << endl << endl;
}
void Feature_COW() {
cout << "Cow goes \'MOO\'." << endl << endl;
}
void Feature_FROG() {
cout << "Frog goes \'CROAK\'." << endl << endl;
}
void Feature_ELEPHANT() {
cout << "And elephant goes \'TOOT\'" << endl << endl;
}
void Feature_DUCK() {
cout << "Duck say \'QUACK\'." << endl << endl;
}
void Feature_FISH() {
cout << "And fish go \'BLUB\'." << endl << endl;
}
void Feature_SEAL() {
cout << "And the seal goes \'OW OW OW\'" << endl << endl;
}
void Feature_FOX() {
cout << "What the fox say!!!" << endl;
cout << "\'Ring-ding-ding-ding-dingeringeding!" << endl;
cout << "Gering-ding-ding-ding-dingeringeding!" << endl;
cout << "Gering-ding-ding-ding-dingeringeding!" << endl << endl;
cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl;
cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl;
cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl << endl;
cout << "Hatee-hatee-hatee-ho!" << endl;
cout << "Hatee-hatee-hatee-ho!" << endl;
cout << "Hatee-hatee-hatee-ho!" << endl << endl;
cout << "Joff-tchoff-tchoff-tchoffo-tchoff!" << endl;
cout << "Tchoff-tchoff-tchoff-tchoffo-tchoff!" << endl;
cout << "Joff-tchoff-tchoff-tchoffo-tchoff!\'" << endl << endl;
}
Last edited on
My question is that do i have to number or declare each to a number certsin set of number to let it then display.

(*sigh*)
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.
@BattleCrazy99

Here's how I would shorten it up. One function call is all that's needed.

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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Animal Menu.cpp : main project file.

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <string>

using std::cout;
using std::cin;
using std::endl;
using std::string;

// Function Prototype.
void Animal_Sound(int);

int main() 
{
	int useranswer;
	// YOUR MENU IMPLEMENTATION GOES HERE
	do
	{
		cout << "+------------------------------------+" << endl;// menu header
		cout << "|------------ ANIMAL MENU -----------|" << endl;// menu header
		cout << "+------------------------------------+" << endl;// menu header
		cout << "1. ) What does the dog say?" << endl;
		cout << "2. ) What does the cat say?" << endl;
		cout << "3. ) What does the bird say?" << endl;
		cout << "4. ) What does the mouse say?" << endl;
		cout << "5. ) What does the cow say?" << endl;
		cout << "6. ) What does the frog say?" << endl;
		cout << "7. ) What does the elephant say?" << endl;
		cout << "8. ) What does the duck say?" << endl;
		cout << "9. ) What does the fish say?" << endl;
		cout << "10.) What does the seal say?" << endl;
		cout << "11.) What does the fox say?" << endl;
		cout << "12.) Exit Program" << endl;
		cout << "Which menu item would you like to execute: ";
		cin >> useranswer;
		if( useranswer <1 ||  useranswer > 12)
		{
			cout << "That doesn't appear to be a valid option. Please try again..." << endl;
			cout << endl << "Which menu item would you like to execute: " << endl << endl;
		}
		if(useranswer > 0 && useranswer < 12)
			Animal_Sound(useranswer);
	}while( useranswer !=12);

	// It's over!
	return 0; // return to OS
}

void Animal_Sound(int choice)
{
	string Animals[11] = {"Dog", "Cat", "Bird", "Mouse", "Cow","Frog","Elephant","Duck","Fish","Seal","Fox"};
	string Sounds[11] = {"WOOF","MEOW","TWEET","SQUEEK","MOO","CROAK","TOOT","QUACK","BLUB","OW OW OW","??"};

	if(choice !=11)
		cout << endl << Animals[choice-1] << " goes '" << Sounds[choice-1] << "'" << endl << endl;
	else
	{
		cout << "What the fox say!!!" << endl;
		cout << "\'Ring-ding-ding-ding-dingeringeding!" << endl;
		cout << "Gering-ding-ding-ding-dingeringeding!" << endl;
		cout << "Gering-ding-ding-ding-dingeringeding!" << endl << endl;
		cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl;
		cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl;
		cout << "Wa-pa-pa-pa-pa-pa-wow!" << endl << endl;
		cout << "Hatee-hatee-hatee-ho!" << endl;
		cout << "Hatee-hatee-hatee-ho!" << endl;
		cout << "Hatee-hatee-hatee-ho!" << endl << endl;
		cout << "Joff-tchoff-tchoff-tchoffo-tchoff!" << endl;
		cout << "Tchoff-tchoff-tchoff-tchoffo-tchoff!" << endl;
		cout << "Joff-tchoff-tchoff-tchoffo-tchoff!\'" << endl << endl;
	}
}
...which is nice, but does not satisfy the homework instructions given to BattleCrazy99.
Topic archived. No new replies allowed.