Feb 20th, 2005, 3:46 PM
|
#1
|
|
Newbie
Join Date: Feb 2005
Posts: 2
Rep Power: 0 
|
Newbie
Hi I am having problem with this program when I run it. I am posting the code at the bottom. Please tell me what am I doing wrong?.
#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 */
int pt_TotalPoints;
printf("\nEnter the maximum grade for each course.\n");
pt_MaxTotalPoints = ReadAddGrades(NumOfGrades, &pt_TotalPoints);
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;
}
Thanks
|
|
|