my c++ code is giving error syntax declaration

int hang(void)
{
    const int maxl=80;
    const int maxt=5;

    int lfill (char,char[],char[]);
    void unitunknown (char[],char[]);
    int m2(void);
    int m2 ()
     {                                            \\the syntax declaration is here
        char unknown [maxl];
        char letter;
        int nwrong=0;
        char word[maxl];
        char words[][maxl]=
        {
        "india",
        "pakistan",
        "australia" ,
        "england",
        "afganistan",
        "bhutan",
        "nepal",
        "malaysia",
        "indonesia",
        "iran",
        "oman" ,
        "china" ,
        "canada" ,
        "denmark" ,
        "japan",
        "gemany" ,
        "france" ,
        "portugal" ,
        "spain",
        "brazil" ,
        "peru" ,
        "mexico"
        };
        randomize();
        int n =random(10);
        strcpy(word,word[n]);
        unitunknown(word,unknown);
        cout<<"\n\t\tWELCOME TO THE GAME OF HANGMAN!!!!";
        cout<<"\nRULES\n1.You have to guess a country's name\n2.Only 5 wrong attempts are allowed.";
        cout<<"\nSo,lets start the game.";
        getch();
        clrscr();
        while(nwrong<maxt)
        {
            cout<<"\n\n"<<unknown;
            cout<<"\n\nGuess aletter:";
            cin>>letter;
            if(lfill(letter,word,unknown)==0)
            {
                cout<<endl<<"Whoops!The letter isn't the one";
                nwrong++;
            }
            else
            {
                cout<<endl<<"You found it!....Yey..";

            }
            cout<<"\n\nYou have "<<maxt-nwrong<<" number of guesses left";
            if(strcmp(word,unknown)==0)
            {
            cout<<word<<endl;
            cout<<"\n\nYeah ,you got it!";
            break;
            }
        }
        if(nwrong==maxt)
        {
            cout<<"\n\nsorry,you have been hanged.";
            cout<<"\nThe word was:"<<word<<endl;
        }
        getch();
        return 0;

        }          

all the sed function have been declared.the error is on '{'

Recommended Answers

All 2 Replies

You appear to be defining a function (m2) inside a function (hang).

I think it would be better if the function prototypes (lines 6,7,8) appeared before any functions.

Oh, and when you make a comment in code, use //, not \

It allso helps if functions aren't nested inside one another. A modern IDE, like CodeBlocks, NetBeans, or Visual Studio, which can all be used for free, helps with gettting these kinds of syntax issues straightened out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.