Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 20th, 2005, 2:46 PM   #1
jat421
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 jat421 is on a distinguished road
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
jat421 is offline   Reply With Quote
Old Feb 20th, 2005, 5:23 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
What errors are you getting? We can't do EVERYTHING for you... we atleast need an error log so we can backtrack your problems
__________________

tempest is offline   Reply With Quote
Old Feb 20th, 2005, 6:15 PM   #3
jat421
Newbie
 
Join Date: Feb 2005
Posts: 2
Rep Power: 0 jat421 is on a distinguished road
Sorry this is the errors I am getting. Please explain it to me as I am a newbie. Thanks

test.c: In function `GetMaxTotalPoints':
test.c:79: too few arguments to function `ReadAddGrades'
test.c:79: void value not ignored as it ought to be
test.c:84: too few arguments to function `ReadAddGrades'
test.c:84: void value not ignored as it ought to be
test.c: In function `ClassGrades':
test.c:106: too few arguments to function `ReadAddGrades'
test.c:106: void value not ignored as it ought to be
test.c: At top level:
test.c:121: conflicting types for `ReadAddGrades'
test.c:6: previous declaration of `ReadAddGrades'
jat421 is offline   Reply With Quote
Old Feb 21st, 2005, 2:42 AM   #4
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
you are only send 1 arguments to

TotalPoints = ReadAddGrades(NumOfGrades);
yet the funtiocn spec is
void ReadAddGrades(int NumOfGrades, int *pt_TotalPoints)

that should solve the big problem ...
Berto is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC