This is what I have so far.. not coming out correct, but am I at least headed in the right direction?

Code:

/* Homework 14 */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void)
{
int flag, x, count=0, j=1,k=1, m=1, n=1, i=1, flag1=0, max, locmax, locmax2, locmax3, locmax4, locmax5;
float sum=0.0, ave;
FILE *exam;
exam = fopen("exam3.dat", "r");
while(fscanf (exam, "%i %i", &flag, &x )==2)
{
if (flag==1)
{
sum = sum + x;
++count;
if (flag1 == 0)
{
max=x;
locmax=j;
locmax2=k;
locmax3=m;
locmax4=n;
locmax5=i;
flag1 = 1;
}
if ( x > max )
{
max = x;
locmax = j;
}
if (x == max )
{
locmax = j;}
if (x == locmax){
locmax2 = k;}
if (x ==locmax2){
locmax3 = m;}
if (x == locmax3){
locmax4 = n;}
if ( x == locmax4){
locmax5 = i;
}
}
++j;
++k;
++m;
++n;
++i;
}
ave = sum/count;
printf("Average = %7.2f \n", ave);
printf("Max = %2i \n", max);
printf("Location of max %2i \n", locmax);
printf("Location of max %2i \n", locmax2);
printf("Location of max %2i \n", locmax3);
printf("Location of max %2i \n", locmax4);
printf("Location of max %2i \n", locmax5);
return 0;
}