I'm trying to find which student has the highest GPA and return the student name. I get an error that says N may be uninitialized and I am not sure why that is the case. Thank you for help!
> I get an error that says N may be uninitialized and I am not sure why that is the case
It should be just a warning (unless there was a compiler option to treat warnings as errors).
With this cleaner version of the code, an added benefit is that the spurious warning would go away:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// return name of topper or "NA" if the list is empty
std::string LinkedListStudent::findTopper() const // *** should be const
{
if( start == nullptr ) return"NA" ;
using node = createNode ; // *** createNode is a poor name for the type node
const node* toppers_node = start ;
for( const node* n = start->next ; n != nullptr ; n = n->next )
{
if( toppers_node->GPA < n->GPA ) toppers_node = n ;
}
// cout << "Student with highest GPA: " << toppers_node->Name << endl << endl;
return toppers_node->name ;
}