Im trying to pass elements of a structure to a function (call by reference)
This code suppose to work like this:
Enter students name and Points
then calculate points to grade in a function.
Code:
#include<stdio.h>
void calculate (struct student *, struct student *);
int main (void)
{
struct student
{
char name[30];
float points;
int grade;
}stud[3];
int i;
for (i=1; i<=3; i++)
{
printf("%d.name->", i); scanf( "%s", &stud[i].name );
printf("points->"); scanf( "%f", &stud[i].points);
calculate ( &stud[i], &stud[i] );
}
return 0;
}
void calculate ( struct student *nname, struct student *pnt )
{
int grade;
grade = ( (*pnt).points < 50 ? 5 : 4-( (int)(*pnt).points - 50 / 15 ) );
printf("\n%sīs grade is %d", (*nname).name, grade);
}