DEV C ++ Error: expected declaration before ‘}’ token

I think you want this:

if (answer == 'd')
{
    cout<< "Your answer is correct. Please press the enter key to proceed to the next question.\n\n";
}
else
    cout<< "The correct answer is D. Please press the enter key to proceed to the next question.\n\n";


getch ();
}
}

To look like this:

if (answer == 'd')
{
    cout<< "Your answer is correct. Please press the enter key to proceed to the next question.\n\n";
} else {
    cout<< "The correct answer is D. Please press the enter key to proceed to the next question.\n\n";
    getch ();
}

It looks like you lost track of your scope immediately following the else.

Leave a Comment