jeudi 19 septembre 2019

Function Call not entering for loop, despite working in other functions

I am calling this function to loop through a vector of structs, and if it matches a certain instance in the vector, it will add grades to an array of the struct. However, it will not enter the for loop to loop through the vector of structs, despite working in other functions just before. In my code I have cout to test if it is entering the for loop properly, but it doesn't

void UploadGrades(long studID, double g1, double g2, double g3, double g4, 
vector<Student> studs){
  for(int i = 0; i < studs.size(); i++){
    cout << "Hi." << endl;
    if(studs[i].id==studID){
      studs[i].grades[0] == g1;
      studs[i].grades[1] == g2;
      studs[i].grades[2] == g3;
      studs[i].grades[3] == g4;
      studs[i].finalGrade = ((g1 + g2 + g3 + g4)/4);
      cout << studs[i].name << " grades successfully uploaded" << endl;
      return;
    }
  }
  cout << "No such student exists, grades cannot be uploaded." << endl;
}

I need it to enter the for loop and go through the proper amount of times updating the grades of the student at location i in the vector, but it doesn't enter the for loop at all

Aucun commentaire:

Enregistrer un commentaire