从阵列打印结果

时间:2015-04-09 01:17:04

标签: c arrays

我正在为学校编写一个程序,它从数据文件中获取信息并填充数组。然后它找到最高,最低并按列计算数字的平均值。我在弄清楚如何打印结果时遇到的麻烦最多。该文件中的数据是6列和15行数字。这是我到目前为止的代码

#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");
  }
}
}
}

此程序将编译时没有任何错误,但它不会运行。我完全迷失了,任何帮助都会非常感激。 谢谢!

1 个答案:

答案 0 :(得分:1)

标准C不允许嵌套函数。

此作业问题/问题与您昨天的帖子相同。

value is neither an array nor a pointer