c++ Need help with array code

Hello everyone, Im trying to allow the user to input his data into an array but its not allowing me and says i need a constant, if any help. would be helpfull


#include
#include
#include
#include
using namespace std;

int main()
{

const double numgrades;
double gradearray[numgrades];


cout<< " How many grades will you be entering today"<<endl;
cin>>numgrades;



Comments

  • Use a dynamic array; the compiler needs to know how much memory to allocate for your array at compile time, but numgrades doesn't have a value until program execution.

    int numgrades;
    // ask for grades.

    double *gradearray = new double[numgrades];

    // when you're done, free the memory
    delete [] gradearray;
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion