/* Peter Cline -- CISC105
   Database of student grades
*/

void printAllInfo(int sID[], double sGPA[], int students);
int addStudent(int sID[], double sGPA[], int students, 
	       int newID, double newGPA);
int addStudentIO(int sID[], double sGPA[], int students);

#include <stdio.h>

int main()
{
  int studentID[50] = {10, 15, 20, 25,
		       30, 35, 40, 45 };
  double studentGPA[50] = {4.0, 3.5, 2.7, 2.9,
			   3.1, 2.5, 3.9, 3.85 };
  int numStudents = 8;

  // function to print out all students' info
  printAllInfo(studentID, studentGPA, numStudents);

  // function to addStudent
  numStudents = addStudentIO(studentID, studentGPA, numStudents);

  printAllInfo(studentID, studentGPA, numStudents);

  printf("Number of students: %d\n", numStudents);

  return 0;
}

void printAllInfo(int sID[], double sGPA[], int students) {
  int i;

  printf("SID\tGPA\n");
  printf("---------------\n");
  for(i = 0; i < students; i++) {
    printf("%d\t%lf\n", sID[i], sGPA[i]);
  }
  printf("\n");
}

int addStudent(int sID[], double sGPA[], int students, 
	       int newID, double newGPA)
{
  sID[students] = newID;
  sGPA[students] = newGPA;

  return students + 1;
}

int addStudentIO(int sID[], double sGPA[], int students) {
  int newID;
  double newGPA;

  printf("Enter the new student ID: ");
  scanf("%d", &newID);

  printf("Enter the new student GPA: ");
  scanf("%lf", &newGPA);

  return addStudent(sID, sGPA, students, newID, newGPA);
  /*
    students = addStudent(sID, sGPA, students, newID, newGPA);
    return students;
   */
}
