I am writing a program to read a list of grades from an array, calculates the average and then gives a grade based on the average. However, I am having debugging issues that I was wondering if anyone with a little more expertise could determine.
proj7.c: In function 'main':
proj7.c:17: error: expected ')' before '}' token
proj7.c:17: error: expected ';' before '}' token
proj7.c: At top level:
proj7.c:18: warning: data definition has no type or storage class
proj7.c:18: error: 'student_grade' undeclared here (not in a function)
proj7.c:18: error: 'grade_size' undeclared here (not in a function)
proj7.c:18: error: void value not ignored as it ought to be
proj7.c:19: warning: data definition has no type or storage class
proj7.c:19: warning: parameter names (without types) in function declaration
proj7.c:19: error: conflicting types for 'compare'
proj7.c:8: error: previous declaration of 'compare' was here
proj7.c:23: error: expected identifier or '(' before 'return'
proj7.c:25: error: expected identifier or '(' before '}' token
proj7.c: In function 'get_data':
proj7.c:42: error: 'input' undeclared (first use in this function)
proj7.c:42: error: (Each undeclared identifier is reported only once
proj7.c:42: error: for each function it appears in.)
proj7.c:42: error: expected ')' before 'status'
proj7.c: In function 'average':
proj7.c:68: warning: 'return' with a value, in function returning void
proj7.c: In function 'compare':
proj7.c:86: error: 'letter' undeclared (first use in this function)
proj7.c:87: error: expected ')' before '}' token
proj7.c:87: error: expected expression before '}' token
proj7.c:89: error: expected expression before 'else'
proj7.c: At top level:
proj7.c:96: error: expected identifier or '(' before '}' token
And heres the code:
Code:
#include <stdio.h>
#define SIZE 15
void get_data(double ar[], int *count);
void average(const double ar[], int count);
void compare(const double ar[], double avg, int count);
int main(void)
{
double student_grade[SIZE];
double student_avg;
int grade_size;
get_data(student_grade, &grade_size};
student_avg= average(student_grade, grade_size);
compare(student_grade, grade_size, student_avg);
return(0);
}
void get_data(double ar[], int *count)
{
FILE *inp;
FILE *outp;
int i = 0;
int input_status;
double grade_1;
inp = fopen("proj7.dat", "r");
outp = fopen("proj7.dat", "w");
input_status = fscanf(inp, "%lf", &grade_1);
while(input status == 1 && i <= SIZE)
{
ar[i] = grade_1;
i++;
fprintf(outp,"%d" "%4.2lf",i, &grade_1);
}
*count = i;
}
void average(const double ar[], int count)
{
double total;
double avg;
int i;
for (i= 0; i <= count; i++)
{
total += ar[i];
}
avg= total/i;
return(avg);
}
void compare(const double ar[], double average, int count)
{
char ltr_grade;
int i;
printf("\n STUDENT NUMBER SCORE GRADE \n");
printf("\n -------------- ----- -----\n");
for(i = 0; i < count; ++i)
{
if(ar[i] <= average-10)
letter = 'F';
if(ar[i] <= average+10}
letter = 'C';
else
letter = 'A';
printf("%3d%9lf%9c \n", i+1, ar[i], ltr_grade);
}
}