Reputation: 31
I'm new to c++ and I'm trying to make a chess game.
Here's the thing I'm trying to make the main menu, and am having trouble. here's the snippit of my code:
int mMenu(int&, char&, bool&, char&);
int main(char&)
{
int choice;
char sure;
bool quit = false;
char ctrl // used for the control from main menu to main()
mMenu (choice, sure, quit);
do
{
if (ctrl == a)
NewGame();
else if (ctrl == b)
LoadGame();
else
quit = true;
}
while (quit == true);
return 0;
}
int mMenu(int& choice, char& sure, bool& quit, char& ctrl,)
{
do
{
cout << " Chess "
<< "------------------------ Main Menu ------------------------\n"
<< "Please choose what operation you'd like to perform from the menu below\n\n"
<< "1. New Game.\n"
<< "2. Load Game.\n"
<< "Exit.\n"
<< "Your choice: ";
cin >> choice;
if (choice == 1)
{
cout << "Are you sure you wish to start a new game? (Y/N) ";
cin >> sure;
if (sure != 'Y')
clrscr();
else
{
ctrl = a;
quit = true;
}
else if (choice == 2)
{
ctrl = b;
quit = true;
}
else if (choice == 3)
{
cout << "Are you sure you wish to exit? (Y/N) ";
cin >> sure;
if (sure != 'Y')
clrscr();
else
{
quit = true;
ctrl = c;
}
}
}
}
while (quit = true);
return ctrl;
}
From that code my compiler (visual c++) is saying that int the main() function, mMenu does not take 3 arguments. What is wrong and how do I make it work?
Thanks in advance.
Also as you can see I'm trying to use clrscr(); but the compiler is flagging it saying it cannot find the definition for it, despite putting in the #include any ideas?
Upvotes: 1
Views: 119
Reputation: 22644
What's wrong is that mMenu does not take 3 arguments. It takes 4.
There are two ways to make this compile:
Upvotes: 0
Reputation: 24413
it is because you have defined mMenu as taking four arguments but call it only with three
mMenu (choice, sure, quit);
Upvotes: 0
Reputation: 20282
It really doesn't take 3 parameters, it takes 4:
int mMenu(int& choice, char& sure, bool& quit, char& ctrl,)
// << the "," in the end
// shouldn't be there
How to fix it? Add the missing parameter:
mMenu (choice, sure, quit, ctrl/*<a ctrl parameter goes here>*/);
You even defined the variable ctrl
, just forgot to pass it as the last argument:-)
Upvotes: 2