I am studying C in college, I'm working on a code that if the GPA of a student is less than 2 >> it adds 0.2 to it
the problem that in debugging ..the value of X = 0 , not equal to f (the return of the function)
#include <stdio.h> #include <stdlib.h> typedef struct user { int userID; char Firstname[25]; float gpa; }; int GPAedit (float x) { float f; if (x < 2) f = x + 0.2; else f = x; return f; } int GPAedit(float); int main() { int i = 0; float x; struct user S[i]; for (i == 0; i < 1; i++) { printf("enter user %d ID", i); scanf("%d", &S[i].userID); printf("enter user %d name\n", i); scanf("%s", S[i].Firstname); printf("enter user %d GPA\n", i); scanf("%f", &S[i].gpa); x = GPAedit(S[i].gpa); S[i].gpa = x; printf("\n\n"); } for (i = 0; i < 1; i++) { printf("user %d ID\n", S[i].userID); printf("%s\n", S[i].Firstname); printf("%.4f\n", S[i].gpa); } }
i == 0should bei = 0typedefsyntax! I learned something today.typedef.