0
I am unable to make the variable char be comparable and validated, the IDE says that the variable 'a' was undeclared, some could help me please
Do a function that receives the 3 notes of a student per parameter and a letter. If a letter is A, calculates the arithmetic mean of the student’s grades, if P, their average weighted (weights: 5, 3 and 2). Use this function in the main program to return the weighted average of a student.
#include <stdio.h>
#include <math.h>
int main ()
{
float x,y,z;
char e;
printf("Digite as 3 notas e uma letra: ");
scanf ("%f %f %f %c", &x, &y, &z, &e);
float ers (float x,float y,float z, char e);
printf("%f %f %f %c", ers(x,y,z,e));
return 0;
}
float ers (float x,float y,float z, char e){
if (e==a)
float media = (x + y + z) / 3;
else if (e==p)
float media = (5*x + y*3 + z*2) / 10;
return media;
}
Or put the function setting before main or at least put the function signature. In this
printf("%f %f %f %c", ers(x,y,z,e));
there’s something missing, maybe you wanted toprintf("%f %f %f %c %f", x, y, z, e, ers(x,y,z,e));
.– anonimo
I didn’t understand, I just wanted to keep the values of the notes and the letter
– Cl2727
Everything makes me understand that you want:
float ers (float x,float y,float z, char e){ if (e=='a') float media = (x + y + z) / 3; else if (e=='p') float media = (5*x + y*3 + z*2) / 10; return media; }
, since it did not define the variablesa
andp
.– anonimo
that’s right, but in the main function at first I wanted to keep the values of notes and a letter, but I can’t keep the letter in the variable char
– Cl2727