I don't have access to a compiler atm, but I would try to cout the variables.
I would cout the variables at the beginning of the for-loop as such:
1 2 3 4
cout << "subjectCode = " << subjectCode << endl;
cout << "subjectCodes[i].name = " << subjectCodes[i].name << endl;
//...etc...for all the variables that might change in the loop.
another thing I would try is to store subjectCodes.size() into a variable. Then the for-loop would look like this :
1 2 3
for (int i = 0; i < size; i++){
//code goes here
}
....because the size of subjectCodes increase. So maybe if you put subjectCodes.size() as the ending parameter, the size increases every time, so the ending parameter is never met.
bool found_it = false ;
for (int i = 0; i < subjectCodes.size(); i++)
{
if (subjectCode == subjectCodes[i].name)
{
subjectCodes[i].count++;
found_it = true ;
break ; // found it, nothing more needs to be done
}
}
if( !found_it ) // did not find it; add a new item to the vector
// and do this just once, not each time through the loop
{
sc.name = subjectCode;
sc.count++;
subjectCodes.push_back(sc);
}