0

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!

6
  • because you never call function. also nested function is non-standard. Commented Apr 9, 2015 at 1:22
  • the function: main() seems to be missing all the code after the variable declarations. Your question says the input file is 6columns by 15rows, but the code does not implement that. Commented Apr 9, 2015 at 1:30
  • when compiling, enable all warnings. then the compiler will tell you much of what is wrong with the posted code. Commented Apr 9, 2015 at 1:32
  • please be consistent with the indentation. suggest indent 4 spaces after each opening brace '{' and un-indent 4 spaces before each closing brace '}'. Such formatting style will make the code MUCH easier to read by us humans and greatly help in the debugging of the code Commented Apr 9, 2015 at 1:34
  • 1
    compiling the posted code gave 9 warnings and 2 errors. The existence of the errors means no executable was produced. Suggest fixing the warnings and the errors. Then if the code still does not work, suggest posting the revised code and a sample of the input file. Commented Apr 9, 2015 at 1:37

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

yeah it is the same, sorry, I'm having a lot of issues with it.
Well I wouldn't mind so much, but you didn't even fix what I pointed out yesterday.
Sorry, I didn't see your answer for my first question until after I posted this one, but thank you for the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.