You need to store the weights in some kind of container with variable size. It's very much recommended to use containers from the standard library, the most typical choice is std::vector
.
#include<vector>
#include<algorithm> //contains std::accumulate, for calculating the averaging-sum
int main(int argc, char *argv[])
{
int number_of_students;
cout << "How many students would you like to add?: ";
cin >> number_of_students;
cout << endl;
cout << endl;
cout << "--------------------------------------------" << endl;
cout << "---------- ENTER STUDENT'S WEIGHT ----------" << endl;
cout << "--------------------------------------------" << endl;
cout << endl;
std::vector<float> weights(number_of_students);
for(int i=0; i<number_of_students; ++i) {
cin >> weights[i];
}
cout << "Average is: " << std::accumulate(weights.begin(), weights.end(), 0.f)
/ number_of_students
<< std::endl;
return EXIT_SUCCESS;
}