C Programming Challeging question..Please Help!! T.T

SamTheGreat's Avatar, Join Date: Oct 2010
Newbie Member
Hi experts,

This is my college project..i have tried it a lot of times but compilation keeps failing and i have run out of idea...please somebody if u see this..please give a helping hand...i appreciate very very much if someone could help...the question is as follows:

• Define a structure with the following data members:
• studid (use char array of 10 elements to store the Student ID)
• lectatt (use int array of 14 elements to store 14 weeks of lecture attendance).
• Use the preprocessor directive to define constants for elements in both arrays.

• In main() function :
• Declare an array of structure variable mystudents with 7 elements. Use the preprocessor directive to define the constant for this array also.
• Declare a pointer to a file called input_file.
• Declare and initialize the following arrays of variable.
o hours_attended (total hours attended for each students)
o att_percentage (the percentage of attendance based on the assumption that students need to attend 2 hours of lecture every week)
• Use the fopen() function call to open a file named attendance.dat for read only and assign the return value the pointer of the input_file.
• Check whether the attendance.dat can be open or not.
• If the file can be opened, use a nested for loop the insert data in the array of structure mystudents.
o Use the outer for loop to read the Student ID and insert the data into the structure array.
o Use the inner for loop to read the attendance where each number represent the number of hours attended.
• Close the input file.
• Create another nested for loop just like the first nested loop to get the total hours attended and get the percentage (assuming that students need to attend 2 hours every week for 14 weeks).
• Use the last for loop to display the Student ID and the attendance percentage for each student.

Thanking you in advanced, and best regards,
C programming Student
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Did you try to write the whole lot in one go before compiling it? This seems a very common beginner mistake. NOBODY writes code that way - except beginners. So:

In main() function :
Declare an array of structure variable mystudents with 7 elements. Use the preprocessor directive to define the constant for this array also.

Stop right there. Before you go any further do you love me? Oops, sorry, got into a Meatloaf song there. Um, before you go any further, compile it. Any errors? Fix them. Now:

Declare a pointer to a file called input_file.

Stop again. Compile it. Any errors? Fix them. And so on. Baby steps; that's the only way to write code. As you get more experience, your baby steps get bigger, but not much. I started programming in 1981 and I still don't write more than 10-15 lines of code before getting the compiler's opinion on what's happening. All my programs start with a "Hello world", when that works OK I then get on and write a bit of code.
SamTheGreat's Avatar, Join Date: Oct 2010
Newbie Member
hi xpi0t0s,

Thanks alot for your advise. I've figured out the solution and get it done on time. Thanks for everything. Take care^^

Best and Warmest regards,
SAM