1

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?

8
  • 3
    You've defined a function that takes 4 arguments, but you've only provided 3 parameters when you try to call it. Commented Dec 4, 2011 at 0:22
  • @OliCharlesworth put it as an answer! :) Commented Dec 4, 2011 at 0:23
  • int mMenu(int& choice, char& sure, bool& quit, char& ctrl = 0) last parameter with default value Commented Dec 4, 2011 at 0:28
  • Note: int main(char&) in the global namespace should not compile cleanly for a hosted implementation. Commented Dec 4, 2011 at 1:03
  • Note 2: char ctrl is missing a semicolon and shouldn't compile. Commented Dec 4, 2011 at 1:05

3 Answers 3

2

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:-)

Sign up to request clarification or add additional context in comments.

1 Comment

OMG! I'm such an idiot XD I guess that was THE most noobiest question you have ever answered! Thank you so much :L
0

it is because you have defined mMenu as taking four arguments but call it only with three

mMenu (choice, sure, quit);

Comments

0

What's wrong is that mMenu does not take 3 arguments. It takes 4.

There are two ways to make this compile:

  • Change mMenu so that it takes 3 arguments.
  • Call mMenu with its current 4 arguments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.