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.
// 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>
usingnamespace std;
// Function prototypes - definitions for these will be AFTER main()
char MakeMenuSelection();
void DisplayAnimalKingdomMessage();
void DisplayEPCOTMessage();
void DisplayHollywoodStudiosMessage();
void DisplayMagicKingdomMessage();
// Constants for menu options
constchar ANIMAL_KINGDOM = 'A';
constchar EPCOT = 'E';
constchar HOLLYWOOD_STUDIOS = 'H';
constchar MAGIC_KINGDOM = 'M';
constchar 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 . . .
*/
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.
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.
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.