I am having a hard time with my program (I'm still getting used to arrays). It's supposed to show a table for students and their grades, and then showing what each student made. Here is my code for the main:
ConstantsCode:#include <stdio.h> #include "constant.h" int readValues(int[]); int findMedian(int[], int); extern void bubblesort(int[], int); int main() { int i,j; int median[EXAMSCORES],meanExam[EXAMSCORES],meanStudent[NUMBERofSTUDENTS]; int grade[NUMBERofSTUDENTS],counts[101]; int scores[NUMBERofSTUDENTS][EXAMSCORES]; int sum=0; for ( i = 0; i < NUMBERofSTUDENTS; i++) { for(j=0;j<EXAMSCORES;j++) { sum+=scores[i][j]; } } for(i=0;i<EXAMSCORES;i++) { for(j=0;j<NUMBERofSTUDENTS;j++) { grade[j]=scores[j][i]; } bubblesort(grade,NUMBERofSTUDENTS); median[i]=grade[NUMBERofSTUDENTS/2]; } for(i=0;i<NUMBERofSTUDENTS;i++) { for(j=0;j<EXAMSCORES;j++) { sum+=scores[i][j]; } meanStudent[i]=sum/EXAMSCORES; } for(i=0;i<EXAMSCORES;i++) { for(j=0;j<NUMBERofSTUDENTS;j++) { sum+=scores[j][i]; } meanExam[i]=sum/NUMBERofSTUDENTS; } for(i = 0; i < EXAMSCORES; i++) { for(j=0;j<NUMBERofSTUDENTS;j++) { counts[scores[j][i]++]; } //printf the distribution for each exam here //printf("Student | Exam %d | Std Avg\n",i); //printf("Student %d | %d | %d\n",counts[i],j,meanStudent[NUMBERofSTUDENTS]); //printf("Exam Avg | %d | %d\n",meanExam[EXAMSCORES]); //printf("Exam Median | %d | %d\n",median[EXAMSCORES]); //printf("EXAM GRADE DISTRIBUTION:\n"); for(i=0;i<101;i++) { if(counts[i]!=0) { printf("Score %d : %d - %d above, %d below ",i,counts[i],grade[NUMBERofSTUDENTS],grade[EXAMSCORES]); //declare varioubles : e.g. int above,below; in the main.... } } printf("\n"); } return 0; } int readValues(int scores[]) { int thisScore; int i = 0; if (scanf("%d",&thisScore) != 1) return i; while( thisScore != -999 ) { scores[i++] = thisScore; assert(i < NUM); // make sure that i < 101 if (scanf("%d",&thisScore) != 1) // get the next score break; } return i; }
BubblesortCode:#define NUMBERofSTUDENTS 200 #define EXAMSCORES 4
If anyone can help me that would be great. I am still new to arrays, so if anyone can help me with naming variables and such I would appreciate it. In case I missed anything here is a link to the assignment http://www.cse.unt.edu/~donr/courses.../program3.htmlCode:void bubblesort(int a[], int arraynum) { int i, j; int temp; for(i = 0; i < arraynum-1; i++) { for( j = 0; j < arraynum-i-1; j++) { if( a[j] > a[j+1] ) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } }


Reply With Quote
Bookmarks