Homework Problem: I do not understand how to "define" functions

I need help with writing definitions for the 4 functions. I have no idea what I am doing wrong. I believe my mistake may have been somewhere in step 1 but I am unsure.

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
// Demonstrate using functions to break-down a program
// into separate tasks.  The main() function provides
// the main program loop, but all other tasks are
// delegated to other functions.

#include<iostream>
#include<iomanip>
using namespace std;

// Function prototypes - definitions for these will be AFTER main()
char MakeMenuSelection();			
void DisplayAnimalKingdomMessage();
void DisplayEPCOTMessage();
void DisplayHollywoodStudiosMessage();
void DisplayMagicKingdomMessage();

// Constants for menu options
const char ANIMAL_KINGDOM		= 'A';                     
const char EPCOT				= 'E';
const char HOLLYWOOD_STUDIOS	= 'H';
const char MAGIC_KINGDOM		= 'M';
const char QUIT					= 'Q';

int main()
{	
	char menuSelection;						// input for menu choice	
	bool done = false;					    // flag for loop control
	
	// Loop to allow the user to repeatedly make menu selections until they are done
    do
    {
		// Display menu and retrieve user's selection
		// Note: This function returns a value, which is assigned to menuSelection
		menuSelection = MakeMenuSelection();   // Call the MakeMenuSelection function

		// Process menu response.
		switch (menuSelection)
		{
			case ANIMAL_KINGDOM:
				// TODO: call the function that displays the Animal Kingdom message
				DisplayAnimalKingdomMessage();
				cout << "You chose Animal Kingdom. Be sure to ride Expedition Everest!";
				break;
			case EPCOT:
				// TODO: call the function that displays the EPCOT message
				DisplayEPCOTMessage();
				cout << "You chose EPCOT. Be sure to go on Soarin!";
				break;
			case HOLLYWOOD_STUDIOS:
				// TODO: call the function that displays the Hollywood Studios message
				DisplayHollywoodStudiosMessage();
				cout << "You chose Hollywood Studios. Coming Soon: Star Wars Land!";
				break;
			case MAGIC_KINGDOM:
				// TODO: call the function that displays the Magic Kingdom message
				DisplayMagicKingdomMessage();
				cout << "You chose Magic Kingdom. The Wishes Fireworks are astounding!";
				break;
			case QUIT:
				done = true;
				break;
			default:
				cout << "Incorrect selection, try again." << endl;
		}

    } while( !done );    // end program loop

    cout << "\nEnd Program - ";
}

char MakeMenuSelection()
{
	// Notice that this function returns a value - a valid character entry made by the user
	char ch;

	// display menu
	cout << endl
		 << setw(30) << "       Program Menu       " << endl
		 << setw(30) << "--------------------------" << endl
		 << setw(5) << ANIMAL_KINGDOM		<< " ...... Animal Kingdom     " << endl
		 << setw(5) << EPCOT				<< " ...... EPCOT              " << endl
		 << setw(5) << HOLLYWOOD_STUDIOS	<< " ...... Hollywood Studios  " << endl
		 << setw(5) << MAGIC_KINGDOM		<< " ...... Magic Kingdom      " << endl
		 << setw(5) << QUIT					<< " ...... Quit Program" << endl
		 << setw(30) << "--------------------------" << endl;

	// get user response
	do {
		cout << setw(20) << "Select a Park (or Q to quit): ";
		cin >> ch;
		ch = toupper(ch);
	} while (ch != 'A' && ch != 'E' && ch != 'H' && ch != 'M' && ch != 'Q');

	// Produce a blank line after a valid selection is made
	cout << endl;

	return ch;
}

// TODO: Write definitions for remaining 4 functions
// These functions must have names, parameter lists, and return that exactly match
// the function prototypes provided at the top of this assignment.






// Sample Program Output
/*

           Program Menu
    --------------------------
    A ...... Animal Kingdom
    E ...... EPCOT
    H ...... Hollywood Studios
    M ...... Magic Kingdom
    Q ...... Quit Program
    --------------------------
Select a Park (or Q to quit): a

You chose Animal Kingdom. Be sure to ride Expedition Everest!

           Program Menu
    --------------------------
    A ...... Animal Kingdom
    E ...... EPCOT
    H ...... Hollywood Studios
    M ...... Magic Kingdom
    Q ...... Quit Program
    --------------------------
Select a Park (or Q to quit): E

You chose EPCOT. Be sure to go on Soarin!

           Program Menu
    --------------------------
    A ...... Animal Kingdom
    E ...... EPCOT
    H ...... Hollywood Studios
    M ...... Magic Kingdom
    Q ...... Quit Program
    --------------------------
Select a Park (or Q to quit): h

You chose Hollywood Studios. Coming Soon: Star Wars Land!

           Program Menu
    --------------------------
    A ...... Animal Kingdom
    E ...... EPCOT
    H ...... Hollywood Studios
    M ...... Magic Kingdom
    Q ...... Quit Program
    --------------------------
Select a Park (or Q to quit): M

You chose Magic Kingdom. The Wishes Fireworks are astounding!

           Program Menu
    --------------------------
    A ...... Animal Kingdom
    E ...... EPCOT
    H ...... Hollywood Studios
    M ...... Magic Kingdom
    Q ...... Quit Program
    --------------------------
Select a Park (or Q to quit): 4
Select a Park (or Q to quit): u
Select a Park (or Q to quit): Q


End Program - Press any key to continue . . .
*/
The main() is a function too. It contains statements that do something. Same is true for all functions.

For example, what should the DisplayAnimalKingdomMessage() do?
Hello AlexPlanks,

To add to what keskiverto has said. You have already written one function other than main "char MakeMenuSelection()" that says you know how.

I see prototypes for other functions what I tend to do is copy the prototype up to but not including the ";" then go to the bottom of the file and paste it hit enter and put the {}s and you have a start to your function

Line 41 calls the function and line 42 would be a good candidate to put in the function as a start.

Hope that helps,

Andy
I thank you for your responses.

The only parts that I had to actually do myself were the parts of code under the TODO statements.
My question is mostly pertaining to the second TODO statement

TODO: Write definitions for remaining 4 functions

I was thinking along the lines of something like this:

void DisplayAnimalKingdomMessage()

if (menuSelection == 'A')

But I feel like this setup is wrong. If you could provide an example so that I can understand, I would greatly appreciate it.
closed account (E0p9LyTq)
Look at your sample output. Each message function already has the output text shown, you simply encapsulate it in a function.

For example, when you chose menu selection 'A', you call DisplayAnimalKingdomMessage();

Define the function (you already declared it before main()):
1
2
3
4
DisplayAnimalKingdomMessage()
{
   std::cout << "You chose Animal Kingdom. Be sure to ride Expedition Everest!\n";
}


Remove the output statement in your ANIMAL_KINGDOM case and you are good to go. You should be able to create the other functions.
Thank you so much! I figured my mistake was somewhere around there.

I was able to get the program to run as intended.

I really appreciate your assistance.
closed account (E0p9LyTq)
@AlexPlanks,

learning a new language, human or computer, can be intimidating in the beginning.

If your question(s) have been answered, please "mark as solved." :)
indentation is all over the place, but otherwise it's a well-organized lesson -- props to the teacher! Generally you don't want to go too crazy in main(), and this is an intro to moving isolated tasks to their own methods.
Topic archived. No new replies allowed.