I'm very new to programing. I'm trying to create a program that will allocate the cost of an environmental clean up over a number of insurance companies that insured the contaminated property during the time of contamination based both upon the time they insured the property and their annaul policy limits.
I created a vector to take the name of each insurance company entered by the user. I need dynamic memory allocation becuase sometimes there's two insurers, other times there are 20. I used a for loop similar to the loop below, but I"m at work and don't have access to the actual code I wrote, but it behaved exactly like the following code:
using namespace std;
// no size specified: vector contains
// no elements
cout << "Number of students: " << flush;
cin >> num_students;
for (vector<double>::size_type i = 0; i < num_students; i++)
cout << "Enter marks for student #" << i+1
<< ": " << flush;
cin >> student_marks[i];
Again, I did not write this code, but I modeled mine off of it. The problem is, the loop runs correctly once, and takes the input, but then it just prints out:"Enter marks for student 1 Enter marks for student 2," etc. After the first input, it never asks for the input for Students 2, 3, 4, etc., it just prints out "Enter marks for student . . ." over and over until the loop ends.
Can anyone tell me why?