Im new on c++ and recently, found myself trying to understand why the code above, compile and run, but suddenly after enter the first grade crash, I figgure out that the problem was when i try to use"Grade[i] = GradeStudent " instead the "push_back" function to store the grades, but i don't understand the reason why and i really want to know isn't work that way. I will really appreciate any help. Sorry, if i don't write properly my question, it is the first time i make a question using stakoverflow
pd:( I wrote the preproccesor tagss: #include iostream, vector and iomanip from the standard library). Thank you
int main() {
std::vector<double> Grade;
int i = 0;
double GradeStudent = 0.0;
std::cout << "introduce the vector valúes.\n";
std::cout << "To end introduce -1.\n";
//Add grades
while(true){
std::cout << "Grade[" << i++ <<"] = ";
std::cin >> GradeStudent;
if(GradeStudent == -1){
break;
}
// Grade.push_back(GradeStudent);
Grade[i] = GradeStudent;//-->if i use that,instead the "push_back" the code crash
}
std::cout << std::endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire