This is a HW problem and im confused why my brackets are errors. line 96 i believe. Thank you.

Write your question here.
I don't understand what im doing wrong... I set it to define the last 3 functions and it keeps giving me errors.

// MenuLoop.cpp
// Lab Exercise 8.3

// 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;

void DisplayMenu(char& ch); // function prototypes
void DoThis();
void DoThat();
void DoAnother();

const char QUIT = '0'; // constants for menu options
const char ONE = '1';
const char TWO = '2';
const char THREE = '3';

const char FOUR = '4';
const char q = 'q';


//------------------------------------------------------------------------------

int main()
{
char option; // input for menu choice
bool done; // flag for loop control

// Initialize loop control (flag) variable
done = false;

// Begin loop here. Test loop exit (flag) condition
while( !done )
{

// display menu
DisplayMenu(option);

// Process menu response.

if(option == ONE) // option 1
{
DoThis();
}
else if(option == TWO) // option 2
{
DoThat();
}
else if(option == THREE) // option 3
{
DoAnother();
}
else if(option == QUIT) // set loop exit condition
{
done = true;
}
else // invalid menu response
{
cout << "\nInvalid choice, please try again.\n";
}

} // end program loop

cout << "\nEnd Program - ";
}

//------------------------------------------------------------------------------

// Function definition to display menu and return choice
// through reference paramater ch

void DisplayMenu(char& ch)
{
cout << endl
<< setw(25) << " Program Menu " << endl
<< setw(25) << "---------------------" << endl
<< setw(5) << ONE << " ...... Do This " << endl
<< setw(5) << TWO << " ...... Do That " << endl
<< setw(5) << THREE << " ...... Do Another " << endl
<< setw(5) << QUIT << " ...... Quit Program" << endl
<< setw(25) << "---------------------" << endl;

// get user response
cout << setw(20) << "Enter option: ";
cin >> ch;
}

//------------------------------------------------------------------------------

// TODO: Write definitions for remaining 3 functions
{
if (option == FOUR)
{
cout << "Invalid choice, please try again." << endl;
}

else if (option == q)
{
cout << "Invalid choice, please try again." endl;
}
else (option == QUIT)
{
done = true;
}







//------------------------------------------------------------------------------

/*

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: 1

Do Option 1 stuff

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: 2

Do Option 2 stuff

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: 3

Do Option 3 stuff

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: 4

Invalid choice, please try again.

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: q

Invalid choice, please try again.

Program Menu
---------------------
1 ...... Do This
2 ...... Do That
3 ...... Do Another
0 ...... Quit Program
---------------------
Enter option: 0

End Program - Press any key to continue . . .
*/

Last edited on
Please use code tags: http://www.cplusplus.com/articles/z13hAqkS/

After the DisplayMenu function, you just have random code hanging around. It must be inside a function otherwise you'll get errors like you mentioned.
I see you don't like magic variables.
I give you :
MAGIC VARIABLES:
1
2
const char FOUR = '4';
const char q = 'q';

I see you like to write extra code:
I give you:
EXTRA CODE:
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
//------------------------------------------------------------------------------

// TODO: Write definitions for remaining 3 functions
{
if (option == FOUR)
{
cout << "Invalid choice, please try again." << endl;
}

else if (option == q)
{
cout << "Invalid choice, please try again." endl;
}
else (option == QUIT)
{
done = true;
}







//------------------------------------------------------------------------------

/* */

fyi if you wanted to comment this out, this would need to be:(However you should just delete this code.
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
//------------------------------------------------------------------------------

// TODO: Write definitions for remaining 3 functions
/*
{
if (option == FOUR)
{
cout << "Invalid choice, please try again." << endl;
}

else if (option == q)
{
cout << "Invalid choice, please try again." endl;
}
else (option == QUIT)
{
done = true;
}







//------------------------------------------------------------------------------
*/

Last edited on
Topic archived. No new replies allowed.