0

I need your help to solve this problem

int main()
{
    int i, n;
 
    
    cout << "\nEnter The Number of Players\n\n";
    cin >> n;


    chess player[n]; 

    for (i = 0; i < n; i++)
    {

        cout << "\nEnter details of " << i + 1 << " Player" << endl;

the error says expression must have constant value and expression did not evaluate to a constant

If someone could help me that would be great

  • 2
    Which part of the error message do you not understand? You must have a constant expression in that location, and you do not have one. – JaMiT Oct 30 '21 at 20:14
  • 1
    Your compiler is correct. In standard `c++` the size of an array must be a compile time constant. – drescherjm Oct 30 '21 at 20:16
  • 1
    Use a std::vector instead of a c array. – infinitezero Oct 30 '21 at 20:16
  • As an example of how one might respond to my earlier comment: The current duplicate assumes that the part of the error message that you did not understand was "why must the expression be constant?" – JaMiT Oct 31 '21 at 01:12
  • How this happens: A couple of the major compilers have extensions that add a C99 feature to C++. People who have only used these compilers assume that these features exist in all C++ compilers. Or you have folks like me who came into C++ from C where this is 100% legal (or at least it was. It's become optional since) and were quite surprised to find that C and C++ are a lot more different than we were taught. – user4581301 Oct 31 '21 at 01:18

0 Answers0