1. -Another adjustment: got rid of int temp. I wasn't using it.

2. Whoops, just realized that I posted the wrong code up there (like I said, I'm brain dead now lol)
Heres the correct one:
Code:
```void sortScores(int finalScores[], int stuID[], int MAX_STUDENT)
{
int current;
int walk;
int tempData;
for(current = 0; current <= MAX_STUDENT - 1; current++)
{
for (walk = current + 1; walk <=  MAX_STUDENT -1; walk++)
if(finalScores[current] < finalScores[walk])
{
tempData = finalScores[current];
finalScores[current] = finalScores[walk];
finalScores[walk] = tempData;
}
}
}```

3. Ok this is almost correct now. However, you need to change the conditions a bit:

Make both conditions < MAX_STUDENT rather than <= MAX_STUDENT - 1. Although it is the same thing, we prefer strict conditions whenever possible (i.e. no equality). You will learn that over time though, it is just how programmers write code.

Indent the code inside your if clause with a tab, so it looks nice.

Now inside the if clause you are currently swapping finalGrades in order to sort them appropriately. Whenever you do that you must also swap stuID[current] with stuID[walk], so that when you print your arrays at the end, student[i] will have the correct initial grade[i] rather than someone else's grade. You do that the same way you swap your scores just after it.

4. Something tells me your program wouldn't work if I entered "62.99" or any similar value.

5. Hold your horses memcpy, we are getting to that.

6. Code:
```void sortScores(int finalScores[], int stuID[], int MAX_STUDENT)
{
int current;
int walk;
int tempData;
for(current = 0; current < MAX_STUDENT - 1; current++)
{
for (walk = (current + 1); walk < MAX_STUDENT - 1; walk++)
if(finalScores[current] < finalScores[walk])
{
tempData = finalScores[current];
finalScores[current] = finalScores[walk];
stuID[current] = stuID[walk];
finalScores[walk] = tempData;
}
}
}```
-Do I need to set tempData equal to stuID?

7. Originally Posted by memcpy
Something tells me your program wouldn't work if I entered "62.99" or any similar value.
I don't think that I have to worry about that. The user is never prompted to enter anything. Everything is already read from a file and assumed to be correct.

8. You got it wrong. Don't change what was previously there in terms of the swap of grades. You just need to do the same thing for the student array. To swap two variables you use a third one tempData. You did that once for finalScores. Do the exact same (same lines) but for the other array after (but still within the if clause, because we only want to swap if that condition is met).

9. I'm a little bit confused by what you mean...
Code:
```void sortScores(int finalScores[], int stuID[], int MAX_STUDENT)
{
int current;
int walk;
int tempData;
for(current = 0; current < MAX_STUDENT - 1; current++)
{
for (walk = (current + 1); walk < MAX_STUDENT - 1; walk++)
if(finalScores[current] < finalScores[walk])
{
tempData = finalScores[current];
tempData = stuID[current];
finalScores[current] = finalScores[walk];
stuID[current] = stuID[walk];
finalScores[walk] = tempData;
studID[walk] = tempData;
}
}
}```
-Is this kind of what its supposed to look like?

10. Or should I make a tempData2 for the stuID or something?

11. This is what you originally had:
Code:
```tempData = finalScores[current];
finalScores[current] = finalScores[walk];
finalScores[walk] = tempData;```
This swaps two numbers, finalScores[current] and finalScores[walk] using an intermediary third, tempData.
Swap stuID[current] and stuID[walk] using the same strategy right after swapping the scores.

More clear?

12. Like this?
Code:
```void sortScores(int finalScores[], int stuID[], int MAX_STUDENT)
{
int current;
int walk;
int tempData;
for(current = 0; current < MAX_STUDENT - 1; current++)
{
for (walk = (current + 1); walk < MAX_STUDENT - 1; walk++)
if(finalScores[current] < finalScores[walk])
{
tempData = finalScores[current];
finalScores[current] = finalScores[walk];
finalScores[walk] = tempData;

tempData = stuID[current];
stuID[current] = stuID[walk]
stuID[walk] = tempData;

}
}
}```

13. I noticed that I missed the ;
I fixed it in my code.

14. Good. You still don't have the conditions for the for correct though. I said change them to be < MAX_STUDENT not < MAX_STUDENT - 1.

Other than that this function looks good for now, post your entire code with the new changes. And make sure it's well indented before posting.

15. Code:
```#include <stdio.h>
#define MAX_STUDENTS 50

int stuID[MAX_STUDENTS];

int finalScores[MAX_STUDENTS];
int getScores();
int calculateScores(char P_N, int homeworkTotal, int midtermTotal, int final, int extraCredit);
void sortScores(int finalScores[], int stuID[], int num_student);
int printToFile();
int main (void)
{

int num_student;
sortScores(&finalScores, &stuID, num_student);
printToFile();

return 0;
}
/*scan the students ID's into an array and scan in each students scores*/
int getScores()
{
int final;
int extraCredit;
int ID;
int ret;
char P_N;

int stu_num;
if (!(spGrades = fopen ("BG_Scores.txt", "r")))
{
}

for(stu_num = 0; stu_num < MAX_STUDENTS; stu_num++){ // no more MAX_STUDENTS
//processing student ID's
if(ret!=1){//until no more student ID's

return stu_num;
}
//process pass or no pass grade

//processing student homework scores

int homeworkTotal = 0;
int i;
int hw;
for (i = 0; i < 8; i++)
{
homeworkTotal = homeworkTotal + hw;

}
homeworkTotal = homeworkTotal + hw;
homeworkTotal /= 9;

// processing midterms

int midtermTotal = 0;
int midterm;

{
midtermTotal = midtermTotal + midterm;
}
midtermTotal /= 2;

//process extra credit
stuID[stu_num] = ID;
finalScores[stu_num] = calculateScores(P_N, homeworkTotal, midtermTotal, final, extraCredit);
}

}

int calculateScores(char P_N, int homeworkTotal, int midtermTotal, int final, int extraCredit)
{

if(P_N != 'P')
return 0;
if(homeworkTotal <= 70)
return 0;
if(midtermTotal <= 60)
return 0;
if(final <= 60)
return 0;

final_grade = ((homeworkTotal + midtermTotal + final + extraCredit) / 3);

}

void sortScores(int finalScores[], int stuID[], int MAX_STUDENT)
{
int current;
int walk;
int tempData;
for(current = 0; current < MAX_STUDENT; current++)
{
for (walk = (current + 1); walk < MAX_STUDENT - 1; walk++)
if(finalScores[current] < finalScores[walk])
{
tempData = finalScores[current];
finalScores[current] = finalScores[walk];
finalScores[walk] = tempData;

tempData = stuID[current];
stuID[current] = stuID[walk];
stuID[walk] = tempData;

}
}
}

int printToFile()
{
FILE* spSorted;

if (!(spSorted = fopen ("BG_Sorted.txt", "w")))
{
}

int i;
int stu_num;

fprintf(spSorted, "Spring 2012\n");
fprintf(spSorted, "CIS 15 BG\n");
fprintf(spSorted, "====\t======\t====\n");
fprintf(spSorted, "====\t======\t====\n");

stu_num = getScores();
for (i =0; i < stu_num; i++){

fprintf(spSorted, "%d\t", stuID[i]);

fprintf(spSorted, "%d\t", finalScores[i]);

if(finalScore >= 97)
fprintf(spSorted, "A+");

else if(finalScore >=93 && finalScore <= 96.9)
fprintf(spSorted, "A");

else if(finalScore >= 90 && finalScore <= 92.9)
fprintf(spSorted, "A-");

else if(finalScore >= 87 && finalScore <=89.9)
fprintf(spSorted, "B+");

else if(finalScore >=83 && finalScore <=86.9)
fprintf(spSorted, "B");

else if(finalScore >=80 && finalScore <= 82.9)
fprintf(spSorted, "B-");

else if(finalScore >=77 && finalScore <=79.9)
fprintf(spSorted, "C+");

else if(finalScore >= 70 && finalScore <= 76.9)
fprintf(spSorted, "C");

else if(finalScore >= 67 && finalScore <= 69.9)
fprintf(spSorted, "D+");

else if(finalScore >= 63 && finalScore <= 66.9)
fprintf(spSorted, "D");

else if(finalScore >= 60 && finalScore <= 62.9)
fprintf(spSorted, "D-");
else
fprintf(spSorted, "F");

fprintf(spSorted,"\n");
}
}
```

Something must be wrong with my declaration for sortScores... the compiler gives me two warnings:
13: warning: passing argument 1 of 'sortScores' from incompatible pointer type
13: warning: passing argument 2 of 'sortScores' from incompatible pointer type