0

Can someone tell me why this code doesn't work? The user inputs a number, let's say 10, and it's saved into an int num. I want to make a double datatype array which can store 10 or num amount of doubles. Why do I keep getting an error when I write it this way?

int num;
cin >> num;
double list[num];

Why is it the above three lines don't work but if I change num in last like to 10 or any other integer it works fine?

int num;
cin >> num;
double list[10];
4
  • 1
    C++ does not allow declaring arrays with a runtime value as the number of entries. Commented Jan 12, 2016 at 3:52
  • Why does C++ not support Variable-length arrays? Commented Jan 12, 2016 at 3:52
  • 6
    And if you want the number to vary: #include <vector> int num; cin >> num; std::vector<int> list(num); Commented Jan 12, 2016 at 3:54
  • thanks guys. Totally makes sence Commented Jan 12, 2016 at 3:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.