ShearForce
ShearForce

Reputation: 23

printing results from array

I am writing a program for school that takes info from a data file and fills an array. It then finds the highest, lowest and calculates the average of the numbers by column. I am having the most trouble with figuring out how to print the results. The data from the file is 6 columns and 15 rows of numbers. Here is my code so far

#include <stdio.h>

/*Define maxes*/
#define STUDENTS 40
#define GRADES 5

/*Declare Functions*/
void getData(int ID[], int Scores[][GRADES], int* numStudents);
void calculate();
void printResults();
void calcHiScore();
void calcLoScore();
void calcAverage();


/*main function*/

int main()
{
/*Variable Declaration*/
   int ID [STUDENTS];
   int Scores [STUDENTS][GRADES];
   int Hi [GRADES];
   int Lo [GRADES];
   double Avg [GRADES];
   int numStudents;

/*getData function called*/
   int getData()
   {
      int student_count;
      int quiz_count;
      FILE* spIn;


      spIn = fopen("myfile.dat", "r");
          student_count=0;
      while (fscanf (spIn, "%d", ID[student_count]) != EOF)  
      {
         for (quiz_count = 0; quiz_count < GRADES; quiz_count++)
         {
            fscanf (spIn, "%d", Scores[student_count][quiz_count]);
         }
      }
   }

/*next calculate function is called*/
   int calculate()
      {
         int calcHiScore (int Scores[][GRADES], int quiz_count, int numStudents)
         {
            int result;
            int student_count;
 result = Scores[0][quiz_count];
        for (student_count=1; student_count< numStudents; student_count++)
        {
           if (Scores[student_count][quiz_count] > result)
              result = Scores[student_count][quiz_count];
        }
        return result;
     }
     int calcLowScore (int Scores[][GRADES], int quiz_count, int numStudents)
     {
        int result;
        int student_count;

            result = Scores[0][quiz_count];
            for (student_count = 1; student_count < numStudents;     student_count++)
            {
               if (Scores[student_count][quiz_count]< result)
                  result = Scores[student_count][quiz_count];
            }
            return result;
         }

/* printResults function called*/

    void printResults(int arr[STUDENTS][GRADES])
    {
       int value[10];
0       int ind;
       int r,c;

       printf("Student\tQuiz1\tQuiz2\tQuiz3\tQuiz4\tQuiz5\n");


/* Print score of all the students in the table form using for loop.*/

   for(r=0;r<15; r++)
   {
      for(c=0;c<6;c++)
      printf("%d\t",arr[r][c]);
      printf("\n");
   }
/* Print the highest, lowest and everage score in each quiz*/

 for(ind=0;ind<3;ind++)
   {
      int v; 
      if(ind==0)
      {

         printf("\nHigh score of quiz\n");
         printf("High\t");
      }  

      if(ind==1)

      {
         printf("\nLow score of quiz\n");
         printf("Low\t");
      }
      if(ind==2)
      {
         printf("\nAverage score of quiz\n");
         printf("Avarage\t");
      }   
/* going through each element of the array*/
      for(c=1;c<6;c++)

      {
         float sum=0;
         v=arr[1][c];
         for(r=0;r<15;r++)
         {
             if(ind==0)
/* Finding highest score in each column*/
             {   
                 if(arr[r][c]>v)
                 v=arr[r][c];
             }
             if(ind==1)   
/* Finding lowest score in each column*/
             if(arr[r][c]<v)
             v=arr[r][c];
             if(ind==2)
             {
/* Finding average score in each column*/   
              sum+=arr[r][c];
             }
         }
         if(ind!=2)
/*print highest and lowest scores*/
         printf("%d\t",v);   
      else
/*print average score in each column*/
      printf("%2.2f\t", sum/15);
      }
      printf("\n");
  }
}
}
}

This program will compile without any errors, but it doesn't run. I'm totally lost, any help would be greatly appreciated. Thank you!

Upvotes: 0

Views: 107

Answers (1)

James T. Smith
James T. Smith

Reputation: 410

Standard C doesn't allow nested functions.

Also this homework problem/question is the same as your yesterday post.

value is neither an array nor a pointer

Upvotes: 1

Related Questions