Hello, this is my first time using the forum so I wasn't sure where to post so I put it in beginner. This is my homework and I try to get code work, so far I was able to get the code to get information from the text file (name.txt). But for some reason when I pass it around to other function to assign the grade and find the highest grade, it didn't do it job and notified me this:
Exception thrown at 0x0FC965F6 (msvcp140d.dll) in Project1.exe: 0xC0000005: Access violation reading location 0xF96C8A1A.
If there is a handler for this exception, the program may be safely continued.
I believe it might be something wrong with my passing with struct but I wasn't sure if it right.
Benjamin James 50
Corine Alise 98
Oscar Amaro 80
Jackson William 87
Allison Sue 23
Kathryn Melissa 56
Philip John 90
Bianca Magali 100
Benjamin Eli 95
Emma Brooks 84
Bojana Jankova 100
Kathleen Jantz 70
Naomi Mast 75
Yanwai Nguyen 73
Kay Ressler 41
Joy Schlabach 79
Ellen Weaver 88
Lynn Wittrig 85
Jieun Han 91
John Graber 68
Also when I try to create a new project on VS and copy paste it to a new cpp file under the new project, the compiler only run the first 2 function but don't run the function to assign the grade and find the highest grade at all
Yea, it was running with that error an hour ago. But when I try to copy paste and throw the code to another .cpp file under a different project. The code run but now it's not running the last 2 function I have on the code.
void findHighestScore(studentType student[array_i])
{
int i;
int max = 0;
for (i = 1; i < array_i; i++)
{
if (student[i].testScore > student[max].testScore)
{
max = i;
}
}
cout << "The student with the highest score is : " << endl;
cout << student[max].studentFName << " " << student[max].studentLName << " with " << student[max].testScore << endl;
// Print out the rest with the same highest score
for (i = max + 1; i < array_i; i++)
{
if (student[i].testScore == student[max].testScore)
{
cout << student[i].studentFName << " " << student[i].studentLName << " with " << student[i].testScore << endl;
}
}
}
The student with the highest score is :
Bianca Magali with 100
Bojana Jankova with 100
Wow, Thank a lot guys, the problem was in the function to find the highest point. I set my maximum point to a 100 so it didn't output my function out. It was a logical error. Thank you all for your help.
Wow, Thank a lot guys, the problem was in the function to find the highest point. I set my maximum point to a 100 so it didn't output my function out. It was a logical error.
It is not just a logical error. The way you implemented your function is completely wrong.
If it's okay, can you explain to me how I implemented my function completely wrong. Please excuse my English, I'm ESL and would love to learn more if I got any mistake
void findHighestScore(studentType student[array_i])
{
int max = 100;
for (int i = 0; i < array_i; i++)
{
if (student[i].testScore > max)
{
student[i].testScore = max;
cout << "The student with the highest score is: " << endl;
cout << student[i].studentFName << " " << student[i].studentLName << " with " << student[i].testScore << endl;
}
}
}
+ First thing : You did not initialize max properly.
+ Second thing : You are supposed to find max, but you change the student score instead when this is what you are not really supposed to.
student[i].testScore = max;
+ Third thing : Assuming you happen to find a student with higher score, you should quietly process all remaining students instead of outputting the student with "max" score outright. It is because there are unprocessed students whose score could be higher. You should only output the students with the highest score at the end of the function, outside your first for loop.
I see. Thank you for your help. It's true that I wasn't pay a careful detail on this function and does it completely wrong. This really help me pay more attention to what I am typing in the future. Thank you kind sir