'pointer' is a terrible name for a variable, btw. Why not name it 'bops' or something?
What type of thing is
pointer[i]
? Is it a
bop*
or a
bop
?
(Remember,
.
is member resolution for structures, and
->
is member resolution for pointers to structures.)
Line 34: This line makes no sense:
-
cin will never be equal to 'q'.
-
$$
does not mean anything.
- You are using
choice before you get it from the user, on line 36.
-
isalpha() returns a boolean, not a
char. Why are you casting it?
Case tags, lines 39, 42, 45, and 48: I think you mean
case 'a':
, etc.
I recommend that your
menu() function be revised to perform the complete action of a menu:
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
|
char menu()
{
char choice;
// Display the menu
cout << "Benevolent Order of Programmers Report\n"
" a. display by name b. display by title\n"
" c. display by bopname d. display by preference\n"
" q. quit\n"
"> "
<< flush;
// Get the user's choice
while (true)
{
cin >> choice;
cin.ignore( 1000, '\n' );
choice = tolower( choice );
if (string("abcdq").find( choice ) != string::npos)
break;
cout << "What? " << flush;
}
return choice;
}
|
Now you can use it naturally:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
bool done = false;
while (!done)
{
switch (menu())
{
case 'a':
// display by name
break;
case 'b':
// display by title
break;
case 'c':
// display by bopname
break;
case 'd':
// display by preference
break;
case 'q':
done = true;
}
}
cout << "Bye!\n";
return 0;
|
Hope this helps.