Hi guys I need some help with pointers. The code below doesn't work. What am I doing wrong?.
And this is the errors I am getting when I compile it.Code:#include <stdio.h> void ReadNumStudents(int* pt_NumStudents); void ReadNumOfGrades(int * pt_NumOfGrades); void GetMaxTotalPoints(int NumOfGrades, int* pt_MaxTotalPoints); void ReadAddGrades(int NumOfGrades, int* pt_TotalPoints); int ReadGrade(int); void ClassGrades(int NumStudents, int NumOfGrades,int MaxTotalPoints); int main() { int NumStudents; /* number of students in class */ int NumOfGrades; /* number of grades for each student */ int MaxTotalPoints; /* total number of possible points */ printf("This program finds the average for each student.\n\n"); ReadNumStudents(&NumStudents); ReadNumOfGrades(&NumOfGrades); GetMaxTotalPoints(NumOfGrades, &MaxTotalPoints); ClassGrades(NumStudents, NumOfGrades, MaxTotalPoints); return 0; } /* * Function to read and return the number of students * Pre: none * Post: The (positive) number of students was returned. */ void ReadNumStudents(int *pt_NumStudents) { /* number of students in class */ printf("How many students are in the class? "); scanf("%d", &pt_NumStudents); while (pt_NumStudents <= 0) { printf("The number of students must be positive.\n"); printf("How many students are there? "); scanf("%d", &pt_NumStudents); } } /* * Function to read and return the number of grades * Pre: none * Post: The (positive) number of grades was returned. */ void ReadNumOfGrades(int *pt_NumOfGrades) { /* number of grades for each student */ printf("How many course grades each student has? "); scanf("%d", &pt_NumOfGrades); while (pt_NumOfGrades <= 0) { printf("The number of course grades must be positive.\n"); printf("How many course grades each student has? "); scanf("%d", &pt_NumOfGrades); } } /* * Function to return the maximum total number of points * possible for a student to earn. * Pre: NumOfGrades is the (positive) number of grades. * Post: The (positive) maximum possible points was returned. */ void GetMaxTotalPoints(int NumOfGrades, int *pt_MaxTotalPoints) { /* total number of possible points */ printf("\nEnter the maximum grade for each course.\n"); pt_MaxTotalPoints = ReadAddGrades(NumOfGrades); while (*pt_MaxTotalPoints <= 0) { printf("The total maximum grade must be positive.\n"); printf("Please enter maximum grade for each course again.\n\n"); pt_MaxTotalPoints = ReadAddGrades(NumOfGrades); } } /* * Function to compute and print the average of each student * Pre: NumStudents is the (positive) number of students. * NumOfGrades is the (positive) number of grades. * MaxTotalPoints is the (positive) total worth of grades. * Post: Each student's average was displayed. */ void ClassGrades(int NumStudents, int NumOfGrades, int MaxTotalPoints) { int student; /* index - which student */ int TotalPoints; /* total number of points */ float average; /* student's average */ for (student = 1; student <= NumStudents; student++) { printf("\nEnter the grades for student %d.\n", student); TotalPoints = ReadAddGrades(NumOfGrades); average = (float)100 * TotalPoints / MaxTotalPoints; printf("\nAverage for student %d = %.1f%%\n",student, average); } } /* * Function to read and total grade and to return total * Pre: NumOfGrades is the (positive) number of grades. * Post: The nonnegative total grade points was returned. */ void ReadAddGrades(int NumOfGrades, int *pt_TotalPoints) { int grade; /* index - which grade */ pt_TotalPoints = 0; for (grade = 1; grade <= NumOfGrades; grade++) pt_TotalPoints += ReadGrade(grade); } /* * Function to read and return an integer grade * Pre: grade is the number of the grade. * Post: A nonnegative grade was returned. */ int ReadGrade(int grade) { int points; /* points for one test*/ do { printf("Enter the nonnegative value of grade %d: ", grade); scanf("%d", &points); }while (points < 0); return points; }
thanksCode:test.c: In function `GetMaxTotalPoints': test.c:78: too few arguments to function `ReadAddGrades' test.c:78: void value not ignored as it ought to be test.c:83: too few arguments to function `ReadAddGrades' test.c:83: void value not ignored as it ought to be test.c: In function `ClassGrades': test.c:105: too few arguments to function `ReadAddGrades' test.c:105: void value not ignored as it ought to be



LinkBack URL
About LinkBacks


