I need some help with my program. The program is supposed to read ID#'s for students as well as grades from a file called "grades.txt" After the program reads the the file it displays a menu as follows: 1. Publish(publish contents of file to output file called "report.txt"); 2. Search(program prompts user to enter ID and display the grades for that specific student); 3. Sort( ask user which field to sort records: valid fields are 0-7 and then print specific records in ascending order like user types 4 and shows all students Exam 2 grades); 4. Projected Grade(calculate official grade/display using formula:

(quiz1+quiz2+exam1+exam2+assignment1+assignment2+assignment3)*0.1+((exam1+exam2)/2)*0.15+LAB =15 

as well as display letter grade: A=90-100, B = 80-89, C= 70-79, D =60-69, F = <60); 5. Distribution(display number of A's, B's, C's, D's and F's in class based on students scores). The "grades.txt" file looks similar to this: 116807 65 31 41 19 15 72 11 // ID quiz1 quiz2 exam1 exam2 assignment1 assignment2 assignment3. This is my code so far:

#include<iostream>
#include<fstream>
using namespace std;

struct students{
       int ID;
       int q1;
       int q2;
       int e1;
       int e2;
       int assg1;
       int assg2;
       int assg3;
       };
int searchList(students grades[], int Num_Students, int ID){
                    int index = 0;
                    bool found =false;
                    while (index < Num_Students && !found){
                          if (grades[index].ID == ID){
                                            found = true;
                                            cout << grades[index].q1;
                                            cout << grades[index].q2;
                                            cout << grades[index].e1;
                                            cout << grades[index].e2;
                                            cout << grades[index].assg1;
                                            cout << grades[index].assg2;
                                            cout << grades[index].assg3;
                                            break;
                                            }
                                            index++;
                                            }
                                            if( found )
                                               return index;
                                            else
                                              return -1;
                                            }

int searchList2(students grades[], int Num_Students, int ID){
    int LAB =15;
    int index = 0;
    bool found = false;
    double total = 0;
    while (index < Num_Students && !found){
          if (grades[index].ID == ID){
                               found = true;
                               total = (grades[index].q1+grades[index].q2
                               +grades[index].e1+grades[index].e2+grades[index].assg1+
                               grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
                             }
                             index++;
                           }
                           if( found ){
                               if (total < 60)
                                              cout << "You have an F" << endl;
                                              else if(total < 69)
                                              cout << " You have a D" << endl;
                                              else if(total < 79)
                                              cout << "You have a C" << endl;
                                              else if(total < 89)
                                              cout << "You have a B" << endl;
                                              else if( total <= 100)
                                              cout << "You have an A" << endl;
                                              return 1;
                                              }
                                          else
                                            return -1;
                               }
void sortList(){
     cout << "'sortList()' not yet initiated!" << endl;
     }




int main(){

    int ID;
    char command;
    int Num_grades = 65;
    students grades[Num_grades];
    int i =0;
    int Num_Students = 65;

    ifstream infile;
    infile.open("grades.txt");

    while(!infile.eof()){
                         infile >> grades[i].ID;
                         infile >> grades[i].q1;
                          infile >> grades[i].q2;
                           infile >> grades[i].e1;
                            infile >> grades[i].e2;
                             infile >> grades[i].assg1;
                              infile >> grades[i].assg2;
                               infile >> grades[i].assg3;
                               i++;
                               }
    ofstream outfile;
    outfile.open("report.txt");
    bool exit = false;


    do{
         cout << "1: Publish grade report" << endl;
         cout << "2: Search for student grade by ID" << endl;
         cout << "3: Sort grades" << endl;
         cout << "4: Projected grade" << endl;
         cout << "5: Distribute grades" << endl;
         cout << endl;
         cout << "Enter an operator: ";
         cin >> command;

         switch (command) {
           case '1':
                for(int j = 0; j<0;j++){
                        outfile << grades[j].ID;
                        j++; 
                }
           break;

           case '2':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList( grades, Num_Students, ID ) == -1);
                cout << "Student not found!" << endl; 
                break;
           case '3':
                sortList();
           break;

           case '4':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList2(grades, Num_Students, ID) == -1 )
                  cout << "Student not found!" << endl;
                break;

           case '5':
                break;

                default:
                        exit = true;

                        }
                     }while( !exit );                                   

    infile.close();
    system("PAUSE");
    return 0;
}

So, I am supposed to do a bubble or selection sort for my case 3 and I don't know that much about it. Does anyone have any suggestions as to how I can begin the sort?

Recommended Answers

All 42 Replies

Ever heard of Google?
Type Selection Sort in C++ . You'll be amazed what you'll find there.

Alright, this is a sort I had originally but I thought someone would have suggestions on something different.

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
       int ID;
       int q1;
       int q2;
       int e1;
       int e2;
       int assg1;
       int assg2;
       int assg3;
       };
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
                    int index = 0;
                    bool found =false;
                    while (index < Num_Students && !found){
                          if (grades[index].ID == ID){
                                            found = true;
                                            cout << grades[index].q1;
                                            cout << grades[index].q2;
                                            cout << grades[index].e1;
                                            cout << grades[index].e2;
                                            cout << grades[index].assg1;
                                            cout << grades[index].assg2;
                                            cout << grades[index].assg3;
                                            break;
                          }
                          index++;
                    }
                    if( found )
                           return index;
                    else
                            return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
    int LAB =15;
    int index = 0;
    bool found = false;
    double total = 0;
    while (index < Num_Students && !found){
          if (grades[index].ID == ID){
                               found = true;
                               total = (grades[index].q1+grades[index].q2
                               +grades[index].e1+grades[index].e2+grades[index].assg1+
                               grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
                             }
                             index++;
                           }
                           if( found ){
                               if (total < 60)
                                              cout << "You have an F" << endl;
                                              else if(total <69)
                                              cout << " You have a D" << endl;
                                              else if(total < 79)
                                              cout << "You have a C" << endl;
                                              else if(total < 89)
                                              cout << "You have a B" << endl;
                                              else if( total <= 100)
                                              cout << "You have an A" << endl;
                                              return 1;
                                              }
                                          else
                                            return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
     for(int m = 0; m < num; m++)
             cout << grades[m] << " ";
     cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
void sortField( students grades[], int num, string sortThis){
     bool swap;
     int temp;
     do{
         swap = false;
         for(int k = 0; k < (num - 1); k++){
                 if(grades[k].ID > grades[k + 1].ID){
                              temp = grades[k].ID;
                              grades[k] = grades[k + 1];
                              grades[k +1].ID = temp;
                              swap = true;

                 }
         }
     }while (swap);
}

                
int main(){
    
    int ID;
    char command;
    int Num_grades = 65;
//grades[] is the array.
    students grades[Num_grades];
    int i =0;
    int Num_Students = 65;
    char sortField;
    string sortList;
    ifstream infile;
    int sortThis;
    infile.open("grades.txt");
    
    while(!infile.eof()){
                infile >> grades[i].ID;
                infile >> grades[i].q1;
                infile >> grades[i].q2;
                infile >> grades[i].e1;
                infile >> grades[i].e2;
                infile >> grades[i].assg1;
                infile >> grades[i].assg2;
                infile >> grades[i].assg3;
                i++;
    }
//Outfile to display all grades.
    ofstream outfile;
    outfile.open("report.txt");
    
    bool exit = false;
//do-while Menu.
    do{
         cout << "1: Publish grade report" << endl;
         cout << "2: Search for student grade by ID" << endl;
         cout << "3: Sort grades" << endl;
         cout << "4: Projected grade" << endl;
         cout << "5: Distribute grades" << endl;
         cout << endl;
         cout << "Enter an operator: ";
         cin >> command;
         
         switch (command) {
//Publish grades to "report.txt"
           case '1':
                for(int j = 0; j<0;j++){
                        outfile << grades[j].ID;
                        j++; 
                }
           break;
//Search for a students grade by ID and output all of their grades.
           case '2':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList( grades, Num_Students, ID ) == -1);
                cout << "Student not found!" << endl; 
                break;
//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "0: Student ID" << endl;
                   cout << "1: Quiz 1 Grade" << endl;
                   cout << "2: Quiz 2 Grade" << endl;
                   cout << "3: Exam 1 Grade" << endl;
                   cout << "4: Exam 2 Grade" << endl;
                   cout << "5: Assignment 1 Grade" << endl;
                   cout << "6: Assignment 2 Grade" << endl;
                   cout << "7: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortField;
                   
                   switch (sortThis){ 
                          case 'ID':
                               sortField(students grades[], int num, string sortThis);
                               showList(grades[].ID, Num_Students);
                               break;
                          case '2':
                               sortList(grades[].q1, Num_Students);
                               showList(grades[].q1, Num_Students);
                               break;
                          case '3':
                               sortList(grades[].q2, Num_Students);
                               showList(grades[].q2, Num_Students);
                               break;
                          case '4':
                               sortList(grades[].e1, Num_Students);
                               showList(grades[].e1, Num_Students);
                               break;
                          case '5':
                               sortList(grades[].e2, Num_Students);
                               showList(grades[].e2, Num_Students);
                               break;
                          case '6':
                               sortList(grades[].assg1, Num_Students);
                               showList(grades[].assg1, Num_Students);
                               break;
                          case '7':
                               sortList(grades[].assg2, Num_Students);
                               showList(grades[].assg2, Num_Students);
                               break;
                          case '8':
                               sortList(grades[].assg3, Num_Students);
                               showList(grades[].assg3, Num_Students);
                               break;
                          default:
                                  cout << "Invalid Command" << endl;
                   }
                }while( !exit ); 
                break;
//Project the letter grade of a specific student by ID.
           case '4':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList2(grades, Num_Students, ID) == -1 )
                  cout << "Student not found!" << endl;
                break;
//Distribute all of the letter grades of all of the students.
           case '5':
                break;     
           default:
                 exit = true;
           }
    }while( !exit );                                   
    
    infile.close();
    system("PAUSE");
    return 0;

I don't like the way this sort is arranged and was wondering if anybody had any suggestions as to how I can create a new one.

If you want us to comment on your sort code, simple past the sort code and thats it.

this is the pseudocode for a bubble sort

procedure bubbleSort( A : list of sortable items ) defined as:
  do
    swapped := false
    for each i in 0 to length(A) - 2 inclusive do:
      if A[ i ] > A[ i + 1 ] then
        swap( A[ i ], A[ i + 1 ] )
        swapped := true
      end if
    end for
  while swapped
end procedure

Compare it with what you have does it look right to you?

The other suggestion was a selection sort
Perhaps that will help you along.

Chris

Here is the code in copy/paste form:

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
int ID;
int q1;
int q2;
int e1;
int e2;
int assg1;
int assg2;
int assg3;
};
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
int index = 0;
bool found =false;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
cout << grades[index].q1;
cout << grades[index].q2;
cout << grades[index].e1;
cout << grades[index].e2;
cout << grades[index].assg1;
cout << grades[index].assg2;
cout << grades[index].assg3;
break;
}
index++;
}
if( found )
return index;
else
return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
int LAB =15;
int index = 0;
bool found = false;
double total = 0;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
total = (grades[index].q1+grades[index].q2
+grades[index].e1+grades[index].e2+grades[index].assg1+
grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
}
index++;
}
if( found ){
if (total < 60)
cout << "You have an F" << endl;
else if(total <69)
cout << " You have a D" << endl;
else if(total < 79)
cout << "You have a C" << endl;
else if(total < 89)
cout << "You have a B" << endl;
else if( total <= 100)
cout << "You have an A" << endl;
return 1;
}
else
return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
for(int m = 0; m < num; m++)
cout << grades[m] << " ";
cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
void sortField( students grades[], int num, string sortThis){
bool swap;
int temp;
do{
swap = false;
for(int k = 0; k < (num - 1); k++){
if(grades[k].ID > grades[k + 1].ID){
temp = grades[k].ID;
grades[k] = grades[k + 1];
grades[k +1].ID = temp;
swap = true;


}
}
}while (swap);
}



int main(){


int ID;
char command;
int Num_grades = 65;
//grades[] is the array.
students grades[Num_grades];
int i =0;
int Num_Students = 65;
char sortField;
string sortList;
ifstream infile;
int sortThis;
infile.open("grades.txt");


while(!infile.eof()){
infile >> grades.ID;
infile >> grades.q1;
infile >> grades.q2;
infile >> grades.e1;
infile >> grades.e2;
infile >> grades.assg1;
infile >> grades.assg2;
infile >> grades.assg3;
i++;
}
//Outfile to display all grades.
ofstream outfile;
outfile.open("report.txt");


bool exit = false;
//do-while Menu.
do{
cout << "1: Publish grade report" << endl;
cout << "2: Search for student grade by ID" << endl;
cout << "3: Sort grades" << endl;
cout << "4: Projected grade" << endl;
cout << "5: Distribute grades" << endl;
cout << endl;
cout << "Enter an operator: ";
cin >> command;


switch (command) {
//Publish grades to "report.txt"
case '1':
for(int j = 0; j<0;j++){
outfile << grades[j].ID;
j++;
}
break;
//Search for a students grade by ID and output all of their grades.
case '2':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList( grades, Num_Students, ID ) == -1);
cout << "Student not found!" << endl;
break;
//Sort IDs or grades into a column.
case '3':
do{
cout << "0: Student ID" << endl;
cout << "1: Quiz 1 Grade" << endl;
cout << "2: Quiz 2 Grade" << endl;
cout << "3: Exam 1 Grade" << endl;
cout << "4: Exam 2 Grade" << endl;
cout << "5: Assignment 1 Grade" << endl;
cout << "6: Assignment 2 Grade" << endl;
cout << "7: Assignment 3 Grade" << endl;
cout << endl;
cout << "Enter field to be sorted(0-7): ";
cin >> sortField;


switch (sortThis){
case 'ID':
sortField(students grades[], int num, string sortThis);
showList(grades[].ID, Num_Students);
break;
case '2':
sortList(grades[].q1, Num_Students);
showList(grades[].q1, Num_Students);
break;
case '3':
sortList(grades[].q2, Num_Students);
showList(grades[].q2, Num_Students);
break;
case '4':
sortList(grades[].e1, Num_Students);
showList(grades[].e1, Num_Students);
break;
case '5':
sortList(grades[].e2, Num_Students);
showList(grades[].e2, Num_Students);
break;
case '6':
sortList(grades[].assg1, Num_Students);
showList(grades[].assg1, Num_Students);
break;
case '7':
sortList(grades[].assg2, Num_Students);
showList(grades[].assg2, Num_Students);
break;
case '8':
sortList(grades[].assg3, Num_Students);
showList(grades[].assg3, Num_Students);
break;
default:
cout << "Invalid Command" << endl;
}
}while( !exit );
break;
//Project the letter grade of a specific student by ID.
case '4':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList2(grades, Num_Students, ID) == -1 )
cout << "Student not found!" << endl;
break;
//Distribute all of the letter grades of all of the students.
case '5':
break;
default:
exit = true;
}
}while( !exit );


infile.close();
system("PAUSE");
return 0;
}

So, can anyone still help me?

commented: no code tags, and seems to be ignoring people +0

Does your Bubble sort work?
If it ain't broke, don't fix it!
There are lots of other sort algorithms out there, but I would not implement a quicksort here, the bubblesort use will do quite well.

I have a problem with the case 1 in the switch "(sortThis)" function. The "sortField" function isn't working and won't compile. I am getting an error that says"multi-character character constant." I don't know if that is a problem but is their anyway to fix it.

Thats because you are declaring variables in the function call....
Chris

Ok, is there anything else that is wrong with the case 1 "sortfield" function call. I can't figure it out.

Other than the fact there is no case 1, then i dont think so....plus im not to sure what case 'ID' is suppose to be...in fact i have no idea.

Chris

Ok, is there anything else wrong with the case 1, "sortField" function. It doesn't compile an I can't figure it out.

an error that says"multi-character character constant."

'ID' has two chars--->multi char? = wrong
'2' has one char --->perfect char constant

I changed some things around a little bit but I still can't find out what is wrong with case 1 that is in case 3 (sortField function). Maybe, I was explaining it wrong. It's okay to put comments on it.

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
int ID;
int q1;
int q2;
int e1;
int e2;
int assg1;
int assg2;
int assg3;
};
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
int index = 0;
bool found =false;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
cout << grades[index].q1;
cout << grades[index].q2;
cout << grades[index].e1;
cout << grades[index].e2;
cout << grades[index].assg1;
cout << grades[index].assg2;
cout << grades[index].assg3;
break;
}
index++;
}
if( found )
return index;
else
return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
int LAB =15;
int index = 0;
bool found = false;
double total = 0;
while (index < Num_Students && !found){
if (grades[index].ID == ID){
found = true;
total = (grades[index].q1+grades[index].q2
+grades[index].e1+grades[index].e2+grades[index].assg1+
grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
}
index++;
}
if( found ){
if (total < 60)
cout << "You have an F" << endl;
else if(total <69)
cout << " You have a D" << endl;
else if(total < 79)
cout << "You have a C" << endl;
else if(total < 89)
cout << "You have a B" << endl;
else if( total <= 100)
cout << "You have an A" << endl;
return 1;
}
else
return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
for(int m = 0; m < num; m++)
cout << grades[m] << " ";
cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
void sortField( students grades[], int num, string sortThis){
bool swap;
int temp;
do{
swap = false;
for(int k = 0; k < (num - 1); k++){
if(grades[k].ID > grades[k + 1].ID){
temp = grades[k].ID;
grades[k] = grades[k + 1];
grades[k +1].ID = temp;
swap = true;


}
}
}while (swap);
}



int main(){


int ID;
char command;
int Num_grades = 65;
//grades[] is the array.
students grades[Num_grades];
int i =0;
int Num_Students = 65;
int sortWhat;
char sortField;
string sortList;
ifstream infile;
int sortThis;
infile.open("grades.txt");


while(!infile.eof()){
infile >> grades.ID;
infile >> grades.q1;
infile >> grades.q2;
infile >> grades.e1;
infile >> grades.e2;
infile >> grades.assg1;
infile >> grades.assg2;
infile >> grades.assg3;
i++;
}
//Outfile to display all grades.
ofstream outfile;
outfile.open("report.txt");


bool exit = false;
//do-while Menu.
do{
cout << "1: Publish grade report" << endl;
cout << "2: Search for student grade by ID" << endl;
cout << "3: Sort grades" << endl;
cout << "4: Projected grade" << endl;
cout << "5: Distribute grades" << endl;
cout << endl;
cout << "Enter an operator: ";
cin >> command;


switch (command) {
//Publish grades to "report.txt"
case '1':
for(int j = 0; j<0;j++){
outfile << grades[j].ID;
j++;
}
break;
//Search for a students grade by ID and output all of their grades.
case '2':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList( grades, Num_Students, ID ) == -1);
cout << "Student not found!" << endl;
break;
//Sort IDs or grades into a column.
case '3':
do{
cout << "1: Student ID" << endl;
cout << "2: Quiz 1 Grade" << endl;
cout << "3: Quiz 2 Grade" << endl;
cout << "4: Exam 1 Grade" << endl;
cout << "5: Exam 2 Grade" << endl;
cout << "6: Assignment 1 Grade" << endl;
cout << "7: Assignment 2 Grade" << endl;
cout << "8: Assignment 3 Grade" << endl;
cout << endl;
cout << "Enter field to be sorted(0-7): ";
cin >> sortWhat;


switch (sortThis){
case '1':
sortField(students grades[], int num, string sortThis);
showList(grades[].ID, Num_Students);
break;
case '2':
sortList(grades[].q1, Num_Students);
showList(grades[].q1, Num_Students);
break;
case '3':
sortList(grades[].q2, Num_Students);
showList(grades[].q2, Num_Students);
break;
case '4':
sortList(grades[].e1, Num_Students);
showList(grades[].e1, Num_Students);
break;
case '5':
sortList(grades[].e2, Num_Students);
showList(grades[].e2, Num_Students);
break;
case '6':
sortList(grades[].assg1, Num_Students);
showList(grades[].assg1, Num_Students);
break;
case '7':
sortList(grades[].assg2, Num_Students);
showList(grades[].assg2, Num_Students);
break;
case '8':
sortList(grades[].assg3, Num_Students);
showList(grades[].assg3, Num_Students);
break;
default:
cout << "Invalid Command" << endl;
}
}while( !exit );
break;
//Project the letter grade of a specific student by ID.
case '4':
cout << "Enter an ID" << endl;
cin >> ID;
if( searchList2(grades, Num_Students, ID) == -1 )
cout << "Student not found!" << endl;
break;
//Distribute all of the letter grades of all of the students.
case '5':
break;
default:
exit = true;
}
}while( !exit );


infile.close();
system("PAUSE");
return 0;
}

i believe i told you that it is because you are declairing variables in the function call......

I refuse to read your code any more until you put it in code tags

commented: I'm already there - welcome to the club +25
commented: Amen +2

I posted the code that way because I thought Freaky_Chris wanted me to post it without code tags. Anyway, what then should I declare in the "sortField" function call if I don't declare the variables that are already in there. Here are the code with code tags:

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
       int ID;
       int q1;
       int q2;
       int e1;
       int e2;
       int assg1;
       int assg2;
       int assg3;
       };
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
                    int index = 0;
                    bool found =false;
                    while (index < Num_Students && !found){
                          if (grades[index].ID == ID){
                                            found = true;
                                            cout << grades[index].q1;
                                            cout << grades[index].q2;
                                            cout << grades[index].e1;
                                            cout << grades[index].e2;
                                            cout << grades[index].assg1;
                                            cout << grades[index].assg2;
                                            cout << grades[index].assg3;
                                            break;
                          }
                          index++;
                    }
                    if( found )
                           return index;
                    else
                            return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
    int LAB =15;
    int index = 0;
    bool found = false;
    double total = 0;
    while (index < Num_Students && !found){
          if (grades[index].ID == ID){
                               found = true;
                               total = (grades[index].q1+grades[index].q2
                               +grades[index].e1+grades[index].e2+grades[index].assg1+
                               grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
                             }
                             index++;
                           }
                           if( found ){
                               if (total < 60)
                                              cout << "You have an F" << endl;
                                              else if(total <69)
                                              cout << " You have a D" << endl;
                                              else if(total < 79)
                                              cout << "You have a C" << endl;
                                              else if(total < 89)
                                              cout << "You have a B" << endl;
                                              else if( total <= 100)
                                              cout << "You have an A" << endl;
                                              return 1;
                                              }
                                          else
                                            return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
     for(int m = 0; m < num; m++)
             cout << grades[m] << " ";
     cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
void sortField( students grades[], int num, string sortThis){
     bool swap;
     int temp;
     do{
         swap = false;
         for(int k = 0; k < (num - 1); k++){
                 if(grades[k].ID > grades[k + 1].ID){
                              temp = grades[k].ID;
                              grades[k] = grades[k + 1];
                              grades[k +1].ID = temp;
                              swap = true;

                 }
         }
     }while (swap);
}

                
int main(){
    
    int ID;
    char command;
    int Num_grades = 65;
//grades[] is the array.
    students grades[Num_grades];
    int i =0;
    int Num_Students = 65;
    int sortWhat;
    char sortField;
    string sortList;
    ifstream infile;
    int sortThis;
    infile.open("grades.txt");
    
    while(!infile.eof()){
                infile >> grades[i].ID;
                infile >> grades[i].q1;
                infile >> grades[i].q2;
                infile >> grades[i].e1;
                infile >> grades[i].e2;
                infile >> grades[i].assg1;
                infile >> grades[i].assg2;
                infile >> grades[i].assg3;
                i++;
    }
//Outfile to display all grades.
    ofstream outfile;
    outfile.open("report.txt");
    
    bool exit = false;
//do-while Menu.
    do{
         cout << "1: Publish grade report" << endl;
         cout << "2: Search for student grade by ID" << endl;
         cout << "3: Sort grades" << endl;
         cout << "4: Projected grade" << endl;
         cout << "5: Distribute grades" << endl;
         cout << endl;
         cout << "Enter an operator: ";
         cin >> command;
         
         switch (command) {
//Publish grades to "report.txt"
           case '1':
                for(int j = 0; j<0;j++){
                        outfile << grades[j].ID;
                        j++; 
                }
           break;
//Search for a students grade by ID and output all of their grades.
           case '2':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList( grades, Num_Students, ID ) == -1);
                cout << "Student not found!" << endl; 
                break;
//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   
                   switch (sortThis){ 
                          case '1':
                               sortField(students grades[], int num, string sortThis);
                               showList(grades[].ID, Num_Students);
                               break;
                          case '2':
                               sortList(grades[].q1, Num_Students);
                               showList(grades[].q1, Num_Students);
                               break;
                          case '3':
                               sortList(grades[].q2, Num_Students);
                               showList(grades[].q2, Num_Students);
                               break;
                          case '4':
                               sortList(grades[].e1, Num_Students);
                               showList(grades[].e1, Num_Students);
                               break;
                          case '5':
                               sortList(grades[].e2, Num_Students);
                               showList(grades[].e2, Num_Students);
                               break;
                          case '6':
                               sortList(grades[].assg1, Num_Students);
                               showList(grades[].assg1, Num_Students);
                               break;
                          case '7':
                               sortList(grades[].assg2, Num_Students);
                               showList(grades[].assg2, Num_Students);
                               break;
                          case '8':
                               sortList(grades[].assg3, Num_Students);
                               showList(grades[].assg3, Num_Students);
                               break;
                          default:
                                  cout << "Invalid Command" << endl;
                   }
                }while( !exit ); 
                break;
//Project the letter grade of a specific student by ID.
           case '4':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList2(grades, Num_Students, ID) == -1 )
                  cout << "Student not found!" << endl;
                break;
//Distribute all of the letter grades of all of the students.
           case '5':
                break;     
           default:
                 exit = true;
           }
    }while( !exit );                                   
    
    infile.close();
    system("PAUSE");
    return 0;
}

Is this a problem:

cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   
                   switch (sortThis){ 
                          case '1':

You're getting the input into sortWhat and then switching on sortThis.

You also have a basic misunderstanding of arrays of structures.

For example in your sort case, you have this in one of the subcases:

sortList(grades[].q1, Num_Students);
    showList(grades[].q1, Num_Students);

You seem to be under the impression that you can generate an array of quiz one scores with grades[].q1 what you have is a syntax error. If you want an integer array containing the quiz one scores, you're going to have to make it.

int q1scores[65];
    for (int ii = 0; ii < Num_Students; ii++)
        q1scores[ii] = grades[ii].q1;

This might come closer to what you're looking for, but I'm not sure.

If you want to be able to sort the entire grades array by different fields in the structure, you would normally write one sort that takes a comparison function (which tells you which record of two would come first) and the helper comparison functions for the different fields you want to sort by.

Your swap inside your bubble sort is also problematic:

if(grades[k].ID > grades[k + 1].ID){
                              temp = grades[k].ID;
                              grades[k] = grades[k + 1];
                              grades[k +1].ID = temp;
                              swap = true;

This saves the ID from structure [k], copies all of the fields from [k+1] to [k] (id, q1, q2, e1, e2, assg1, assg2, assg3), then sets the ID in [k+1] from the saved ID. You lost all of the scores from record [k].

I haven't been getting any compile errors with my "sortField" function or whatever it's supposed to be. I am only getting errors with my call but I changed some thing around and here is the new code:

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
       int ID;
       int q1;
       int q2;
       int e1;
       int e2;
       int assg1;
       int assg2;
       int assg3;
       };
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
                    int index = 0;
                    bool found =false;
                    while (index < Num_Students && !found){
                          if (grades[index].ID == ID){
                                            found = true;
                                            cout << grades[index].q1;
                                            cout << grades[index].q2;
                                            cout << grades[index].e1;
                                            cout << grades[index].e2;
                                            cout << grades[index].assg1;
                                            cout << grades[index].assg2;
                                            cout << grades[index].assg3;
                                            break;
                          }
                          index++;
                    }
                    if( found )
                           return index;
                    else
                            return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
    int LAB =15;
    int index = 0;
    bool found = false;
    double total = 0;
    while (index < Num_Students && !found){
          if (grades[index].ID == ID){
                               found = true;
                               total = (grades[index].q1+grades[index].q2
                               +grades[index].e1+grades[index].e2+grades[index].assg1+
                               grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
                             }
                             index++;
                           }
                           if( found ){
                               if (total < 60)
                                              cout << "You have an F" << endl;
                                              else if(total <69)
                                              cout << " You have a D" << endl;
                                              else if(total < 79)
                                              cout << "You have a C" << endl;
                                              else if(total < 89)
                                              cout << "You have a B" << endl;
                                              else if( total <= 100)
                                              cout << "You have an A" << endl;
                                              return 1;
                                              }
                                          else
                                            return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
     for(int m = 0; m < num; m++)
             cout << grades[m] << " ";
     cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
int sortField(students grades[], int num, string sortThis){
     bool swap;
     int temp;
     do{
         swap = false;
         for(int k = 0; k < (num - 1); k++){
                 if(grades[k].ID > grades[k + 1].ID){
                              temp = grades[k].ID;
                              grades[k] = grades[k + 1];
                              grades[k +1].ID = temp;
                              swap = true;

                 }
         }
     }while (swap);
}

                
int main(){
    
    int ID;
    char command;
    int Num_grades = 65;
//grades[] is the array.
    students grades[Num_grades];
    int i =0;
    int Num_Students = 65;
    int sortWhat;
    char sortField;
    string sortList;
    ifstream infile;
    string sortThis;
    infile.open("grades.txt");
    
    while(!infile.eof()){
                infile >> grades[i].ID;
                infile >> grades[i].q1;
                infile >> grades[i].q2;
                infile >> grades[i].e1;
                infile >> grades[i].e2;
                infile >> grades[i].assg1;
                infile >> grades[i].assg2;
                infile >> grades[i].assg3;
                i++;
    }
//Outfile to display all grades.
    ofstream outfile;
    outfile.open("report.txt");
    
    bool exit = false;
//do-while Menu.
    do{
         cout << "1: Publish grade report" << endl;
         cout << "2: Search for student grade by ID" << endl;
         cout << "3: Sort grades" << endl;
         cout << "4: Projected grade" << endl;
         cout << "5: Distribute grades" << endl;
         cout << endl;
         cout << "Enter an operator: ";
         cin >> command;
         
         switch (command) {
//Publish grades to "report.txt"
           case '1':
                for(int j = 0; j<0;j++){
                        outfile << grades[j].ID;
                        j++; 
                }
           break;
//Search for a students grade by ID and output all of their grades.
           case '2':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList( grades, Num_Students, ID ) == -1);
                cout << "Student not found!" << endl; 
                break;
//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   
                   switch (sortWhat){ 
                          case '1':
                               sortField(Num_Students[], int num, sortWhat);
                               showList(grades[].ID, Num_Students);
                               break;
                          case '2':
                               int q1scores[65];
                               for (int ii = 0; ii < Num_Students; i++)
                               q1scores[ii] = grades[ii].q1;
                               break;
                          case '3':
                               sortList(grades[].q2, Num_Students);
                               showList(grades[].q2, Num_Students);
                               break;
                          case '4':
                               sortList(grades[].e1, Num_Students);
                               showList(grades[].e1, Num_Students);
                               break;
                          case '5':
                               sortList(grades[].e2, Num_Students);
                               showList(grades[].e2, Num_Students);
                               break;
                          case '6':
                               sortList(grades[].assg1, Num_Students);
                               showList(grades[].assg1, Num_Students);
                               break;
                          case '7':
                               sortList(grades[].assg2, Num_Students);
                               showList(grades[].assg2, Num_Students);
                               break;
                          case '8':
                               sortList(grades[].assg3, Num_Students);
                               showList(grades[].assg3, Num_Students);
                               break;
                          default:
                                  cout << "Invalid Command" << endl;
                   }
                }while( !exit ); 
                break;
//Project the letter grade of a specific student by ID.
           case '4':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList2(grades, Num_Students, ID) == -1 )
                  cout << "Student not found!" << endl;
                break;
//Distribute all of the letter grades of all of the students.
           case '5':
                break;     
           default:
                 exit = true;
           }
    }while( !exit );                                   
    
    infile.close();
    system("PAUSE");
    return 0;

I have been continually going back and forth from the "switch (sortWhat)" and the "sortField" call because it gives me a "switch not an integer" error.

Ok, I'm curious, what compiler are you using? (I'm still seeing lots of compile errors.)

I found another basic problem. Inside your main() you declare char sortField which hides the function int sortField(students grades[], int num, string sortThis) This may be related to your current issue.

How are the sub-selections under '3' sort grades supposed to work?

If I select 1, should the output just be a sorted list of IDs? or should the entire grades array be sorted by ID and then output?

If I select 2, should I just see a sorted list of quiz 1 grades or all of the records ordered by the quiz 1 grade?

I am using Dev C++. Thanks for the hint about the "char sortField" because when I removed it the only errors I get is: "expected primary expression before ] token" and "expected primary expression before int." The program goes like this: When the user chooses the sort option, the program should ask the user which field should be used to sort the records. Valid sorting field values are between 0-7. When a valid value has been entered, the program should display data in that column in ascending sorted order. For example, if the user enters 1, then the program should display all the quiz 1 grades in sorted order.

Your code:

//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   
                   switch (sortWhat){ 
                          case '1':
                               sortField(Num_Students[], int num, sortWhat);
                               showList(grades[].ID, Num_Students);
                               break;
                          case '2':
                               int q1scores[65];
                               for (int ii = 0; ii < Num_Students; i++)
                               q1scores[ii] = grades[ii].q1;
                               break;

I moved and renamed the q1scores array (I was getting warnings).
I presumed an alternate version of sortField named sortList that expects an array of integers and a count. It sorts the array.

//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   int scores[Num_grades];
                   
                   switch (sortWhat){ 
                          case '1':
                               for (int ii = 0; ii < Num_Students; i++)
                                   scores[ii] = grades[ii].ID;
                               sortList(scores, Num_Students);
                               showList(scores, Num_Students)
                               break;
                          case '2':
                               for (int ii = 0; ii < Num_Students; i++)
                                   scores[ii] = grades[ii].q1;
                               sortList(scores, Num_Students);
                               showList(scores, Num_Students)
                               break;

Is it supposed to look like this:

#include<iostream>
#include<fstream>
using namespace std;
//Struct students defines each element in the array.
struct students{
       int ID;
       int q1;
       int q2;
       int e1;
       int e2;
       int assg1;
       int assg2;
       int assg3;
       };
//searchList will search inside of the infile for a specific ID of a student and output all of their grades.
int searchList(students grades[], int Num_Students, int ID){
                    int index = 0;
                    bool found =false;
                    while (index < Num_Students && !found){
                          if (grades[index].ID == ID){
                                            found = true;
                                            cout << grades[index].q1;
                                            cout << grades[index].q2;
                                            cout << grades[index].e1;
                                            cout << grades[index].e2;
                                            cout << grades[index].assg1;
                                            cout << grades[index].assg2;
                                            cout << grades[index].assg3;
                                            break;
                          }
                          index++;
                    }
                    if( found )
                           return index;
                    else
                            return -1;
}
//searchList2 will also find the student with a specific ID and output the projected letter grade for that student.
int searchList2(students grades[], int Num_Students, int ID){
    int LAB =15;
    int index = 0;
    bool found = false;
    double total = 0;
    while (index < Num_Students && !found){
          if (grades[index].ID == ID){
                               found = true;
                               total = (grades[index].q1+grades[index].q2
                               +grades[index].e1+grades[index].e2+grades[index].assg1+
                               grades[index].assg2+grades[index].assg3)*0.1 + ((grades[index].e1+grades[index].e2)/2)*.15 + LAB;
                             }
                             index++;
                           }
                           if( found ){
                               if (total < 60)
                                              cout << "You have an F" << endl;
                                              else if(total <69)
                                              cout << " You have a D" << endl;
                                              else if(total < 79)
                                              cout << "You have a C" << endl;
                                              else if(total < 89)
                                              cout << "You have a B" << endl;
                                              else if( total <= 100)
                                              cout << "You have an A" << endl;
                                              return 1;
                                              }
                                          else
                                            return -1;
}
//showList will output the grades in order to the screen.
void showList(int grades[], int num){
     for(int m = 0; m < num; m++)
             cout << grades[m] << " ";
     cout << endl;
}
//sortList is a bubble sort that will sort through a specific field and put into order.
void sortField( students grades[], int num, string sortThis){
     bool swap;
     int temp;
     do{
         swap = false;
         for(int k = 0; k < (num - 1); k++){
                 if(grades[k].ID > grades[k + 1].ID){
                              temp = grades[k].ID;
                              grades[k] = grades[k + 1];
                              grades[k +1].ID = temp;
                              swap = true;

                 }
         }
     }while (swap);
}

                
int main(){
    
    int ID;
    char command;
    int Num_grades = 65;
//grades[] is the array.
    students grades[Num_grades];
    int i =0;
    int Num_Students = 65;
    int sortWhat;
    string sortList;
    ifstream infile;
    int sortThis;
    infile.open("grades.txt");
    
    while(!infile.eof()){
                infile >> grades[i].ID;
                infile >> grades[i].q1;
                infile >> grades[i].q2;
                infile >> grades[i].e1;
                infile >> grades[i].e2;
                infile >> grades[i].assg1;
                infile >> grades[i].assg2;
                infile >> grades[i].assg3;
                i++;
    }
//Outfile to display all grades.
    ofstream outfile;
    outfile.open("report.txt");
    
    bool exit = false;
//do-while Menu.
    do{
         cout << "1: Publish grade report" << endl;
         cout << "2: Search for student grade by ID" << endl;
         cout << "3: Sort grades" << endl;
         cout << "4: Projected grade" << endl;
         cout << "5: Distribute grades" << endl;
         cout << endl;
         cout << "Enter an operator: ";
         cin >> command;
         
         switch (command) {
//Publish grades to "report.txt"
           case '1':
                for(int j = 0; j<0;j++){
                        outfile << grades[j].ID;
                        j++; 
                }
           break;
//Search for a students grade by ID and output all of their grades.
           case '2':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList( grades, Num_Students, ID ) == -1);
                cout << "Student not found!" << endl; 
                break;
//Sort IDs or grades into a column.
           case '3':
                do{
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   int scores[Num_grades];
                   
                   switch (sortWhat){ 
                          case '1':
                               for (int ii =0; ii < Num_Students; i++)
                                    scores[ii] = grades[ii].ID
                               sortList(scores, Num_Students);
                               showList(scores, Num_Students)
                               break;
                          case '2':
                               for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].q1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '3':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].q2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '4':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].e1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '5':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].e2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '6':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '7':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case '8':
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg3
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          default:
                                  cout << "Invalid Command" << endl;
                   }
                }while( !exit ); 
                break;
//Project the letter grade of a specific student by ID.
           case '4':
                cout << "Enter an ID" << endl;
                cin >> ID;
                if( searchList2(grades, Num_Students, ID) == -1 )
                  cout << "Student not found!" << endl;
                break;
//Distribute all of the letter grades of all of the students.
           case '5':
                break;     
           default:
                 exit = true;
           }
    }while( !exit );                                   
    
    infile.close();
    system("PAUSE");
    return 0;
}

Do I need to remove the "sortField" function?

I don't know if this helps but sortWhat is an integer and you are doing case '1' : instead of case 1 :

If you're not going to use sortField, go ahead and remove it.

PS- ddanbe is right

In my sample program, the sort submenu looks like this:

sortExit = false;
                do{
                   char sortCommand;
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << "9: Return to main menu" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(1-8): ";
                   cin >> sortCommand;
                   
                   switch (sortCommand){ 
                          case '1':
                               for (int ii = 0; ii < Num_Students; ii++)
                                   scores[ii] = grades[ii].ID;
                               sortList(scores, Num_Students);
                               showList(scores, Num_Students);
                               break;
                          // 
                          // Skipping cases for 2-8 here
                          // 
                          case '9':
                               sortExit = true;
                               break;
                          default:
                               cout << "Invalid Command" << endl;
                   }
                }while( !sortExit );
commented: respect is mutually, this is a hard one +3

I tried doing what you suggested Murtan and I am getting an error message"Num_Students undeclared. " Yet, I have Num_Students declared after int main(). I also removed the '' from the different cases as ddanbe suggested This is what I have:
case 3:

do{
                    char sortWhat;
                   cout << "1: Student ID" << endl;
                   cout << "2: Quiz 1 Grade" << endl;
                   cout << "3: Quiz 2 Grade" << endl;
                   cout << "4: Exam 1 Grade" << endl;
                   cout << "5: Exam 2 Grade" << endl;
                   cout << "6: Assignment 1 Grade" << endl;
                   cout << "7: Assignment 2 Grade" << endl;
                   cout << "8: Assignment 3 Grade" << endl;
                   cout << endl;
                   cout << "Enter field to be sorted(0-7): ";
                   cin >> sortWhat;
                   int scores[Num_grades];
                   
                   switch (sortWhat){ 
                          case 1:
                               for (int ii =0; ii < Num_Students; i++)
                                    scores[ii] = grades[ii].ID
                              [B] sortList(scores, Num_Students);[/B]//problem here
                               showList(scores, Num_Students)
                               break;
                          case 2:
                               for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].q1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 3:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].q2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 4:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].e1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 5:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].e2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 6:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg1
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 7:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg2
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          case 8:
                                  for (int ii =0; ii < NumStudents; i++)
                                    scores[ii] = grades[ii].assg3
                               sortList( scores, Num_Students);
                               showList( scores, Num_Students)
                               break;
                          default:
                                  cout << "Invalid Command" << endl;
                   }
                }while( !exit ); 
                break;

Can you run it yet?

What does it do?

No, it won't compile or run yet. The problem is in here:

switch (sortWhat){ 
                          case 1:
                               for (int ii =0; ii < Num_Students; i++)
                                    scores[ii] = grades[ii].ID
                               [B]sortList(scores, Num_Students);[/B]<-- problem right here
                               showList(scores, Num_Students)
                               break;

The "sortList" won't compile it says "Num_Students undeclared" also I get a bunch of "expected before sortList" and "expected before break" errors. Hope, this is a better explanation.

sortList won't compile because it is called sortField, so you have no sortList method I think

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.