I am new to programming in C and I am making a C program to find the average and percentage of marks obtained by a student in three subjects using a single function. My code is:
#include <stdio.h>
int main()
{
float aver, per, mark1, mark2, mark3;
printf("Enter the marks of subject 1: ");
scanf(" %f", &mark1);
printf("Enter the marks of subject 2: ");
scanf(" %f", &mark2);
printf("Enter the marks of subject 3: ");
scanf(" %f", &mark3);
averper(mark1, mark2, mark3, &aver, &per);
printf("The average of marks entered by you = %f\n", aver);
printf("The percentage of marks entered by you = %f", per);
return 0;
}
float averper(float a, float b, float c, float *d, float *e)
{
float sum = a + b + c;
*d = sum / 3;
*e = (sum / 300) * 100;
}
The errors obtained are:
main.c: In function ‘main’: main.c:11:2: warning: implicit declaration of function ‘averper’ [-Wimplicit-function-declaration] averper(mark1, mark2, mark3, &aver, &per); ^~~~~~~ main.c: At top level: main.c:16:7: error: conflicting types for ‘averper’ float averper(float a, float b, float c, float *d, float *e) ^~~~~~~ main.c:11:2: note: previous implicit declaration of ‘averper’ was here averper(mark1, mark2, mark3, &aver, &per); ^~~~~~~
Thanks