Arrays and pointers problem!!

The program should ask the user how many students were surveyed and dynamically allocate an array of that size. The program should then allow the user to enter the number of movies each student has seen.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  #include <iostream>
  #include <string>
  using namespace std;

  int main()
  {
	int numStudents;
	double *movies;

	cout << "How many students were surveyed?" << endl;
	cin >> numStudents;

	while(numStudents <= -1)
	{
		cout << "Enter a positive number." << endl;
		cin >> numStudents;
	}
	movies = [numStudents];

	return 0;
  }


The problem I'm having is that where I declare movies = [numStudents]; the semicolon after the numStudents array is giving me this error - "error: expected a '{' introducing a lambda body". I been stuck for a very long time and I have no clue why it's giving me this error.
movies = new double[numStudents];
thank you, that worked! Can you please explain to me why it worked?? What is the purpose of "new double" ?
It works because it is a valid C++ construction.:)

it allocates memory for an array of numStudents elements and assigns the address of the fiirst element to variable movies.
Thank you!
Topic archived. No new replies allowed.