Menu Function Code check

Don't have access to a compiler today to test my code and asking someone to look this code over for errors or improvement areas. Basically I have written a part of the main which calls this function and prompts a player to make a choice between two letters. If they choose an 'F' or 'f' it will move on to another function that asks them for more information and processes that into an array. Hope to have that code done by tonight. As always appreciate the comments and assistance. This site has taught me quite a bit more than a book.

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
  #include <iostream>
#include <fstream>
#include <string>

using namespace std;

//reference to functions that will be used

char menu(); //function prototype for menu
void processUserInput();//prototype to handle entered characters
string readLegalWords();//prototype to process contents of file into an array
string findWords(); //prototype that will compare entered characters against array of strings




int main {

char menuChoice;//variable to hold user choice

cout<<"Welcome to TLW Game."<<endl; //display to screen the game name

/*first function called will be menu function which will drive the rest of the
game and othe function calls*/

char menu(); //the rest of the functions will be called within each other

system("Pause");
return 0;
}

void menu();
{
    char menuChoice;
    cout<<"Enter your Choice:"<<endl;
    cout<<"(F)ind Words"<<endl;
    cout<<"(Q)uit"<<endl;
    cin>>menuChoice;
    cout<<"Choice:  "<<menuChoice<<endl;
	while(menuChoice != 'Q' || menuChoice != 'q')
	{

	if(menuChoice == 'F' && menuChoice == 'f')
 	    {
		//call to process user input function
		processUserInput();
	    }
	else if(menuChoice =='Q' || menuChoice == 'q')
	    {
                 cout<<"Thanks for Playing TLW."<<endl;
            }

	  }
}
Well first off, in your prototype for the menu function you are saying that it will return a char, as well as when you call it, but once you write the function you are saying that it returns void, so that will give you problems.

Also you will run into an infinite loop if you enter a character other than Q or F because it will go in since it isn't Q and will check the if statements forever. You also have an untrue statement in your first if statement, menuChoice cannot be 'F' and 'f' at the same time, so you should change that to an or condition.

Other than that the rest of your code looks like it will work.

Have fun programming. :)
Topic archived. No new replies allowed.