Hello everyone, this is my first post on the forum.
I need to do a project for my uni in C, unfortunately I'm learning C for quite short time, which is very stupid of me, now I started spending a lot of time with C, but everything is still very mixed up for me, and time for my project is running out.
I have to write following program:
a) Define a structure called "data" which contains 2 elements, string to store name and string to store surename
b)Define structure called "student" which contains: structure "data", an array to store grades and variable that stores the average value of grades
c)In main() declare an array of structures type "student"(SIZE=4), initialize the elements of structure "data" with names of the students
Use functions for d,e,f,g
d)Ask user to enter grades of students and put them in element "grades" in a structure
e) Calculate the average value of grades for each structure and pin it on to the proper element
f) Print informations contained in each structure
g) Print the average value of grades for each student
I need to do it in at least 2 files, so I figured I'm gonna put functions in one file and main() in the other.
You can see my code below, so far I have covered a,b,c,d, however I didn't use functions. At the moment I'm pretty much stuck, so help will be greatly appreciated!
Code:#include <stdio.h> #include <stdlib.h> #define MAX 4 struct data { char name[20]; char surename[20]; }; struct student { struct data data_s; float average; int grades[10]; }; int main(int argc, char* argv[]) { struct student students[MAX]; int counter = 0; printf("Name of the first student: "); gets(students[counter].data_s.name); while (counter < MAX) { printf("Student's surename: "); gets(students[counter++].data_s.surename); if (counter < MAX) { printf("Name of the next student: "); gets(students[counter].data_s.name); } } int i; int counter_grades; for (i = 0; i < MAX; ++i) { printf("Grades of the student %d: ", i + 1); for (counter_grades = 0; counter_grades < MAX; ++counter_grades) { if (0 == scanf("%f", &students[i].grades[counter_grades])) break; } fflush(stdin); } system("PAUSE"); return 0; }