Working with arrays of structures, need advice...
Brand new C programmer here.
I'm working on a program, and am about 75% done...stumped on 3 things though.
1. One of the fields in my structure is student GPA. I need to calculate all of the GPA's to return a class average. What would be the best way to determine the number of students, if the number to be divided by is not known when the program is started (works off user input, and there is not a predetermined number of inputs...could be 5, could be 50).
2. What is the best way to remove a record from memory, based on "Last Name" as the key field.
3. One of the inputs I'm receiving from the user is "Number of children". I've got a get_student_info function that I'm using to get input from the user...I'm not exactly sure of the syntax I would need to set up an "if" structure to check the number of children field to also prompt the user for child name & age if they respond 1 or more to the number.
Any help would be appreciated.
Re: Working with arrays of structures, need advice...
Quote:
Originally posted by Unregistered
Brand new C programmer here.
I'm working on a program, and am about 75% done...stumped on 3 things though.
1. One of the fields in my structure is student GPA. I need to calculate all of the GPA's to return a class average. What would be the best way to determine the number of students, if the number to be divided by is not known when the program is started (works off user input, and there is not a predetermined number of inputs...could be 5, could be 50).
2. What is the best way to remove a record from memory, based on "Last Name" as the key field.
3. One of the inputs I'm receiving from the user is "Number of children". I've got a get_student_info function that I'm using to get input from the user...I'm not exactly sure of the syntax I would need to set up an "if" structure to check the number of children field to also prompt the user for child name & age if they respond 1 or more to the number.
Any help would be appreciated.
1. int numberofstudents = 0;
// after each successful input
numberofstudents++;
2. post some code
3. if (numberofkids > 0)
{ // take more input
}
i'm sorry i can't be more specific, try posting some code
Re: Working with arrays of structures, need advice...
Quote:
Originally posted by moi
1. int numberofstudents = 0;
// after each successful input
numberofstudents++;
2. post some code
3. if (numberofkids > 0)
{ // take more input
}
i'm sorry i can't be more specific, try posting some code
1. Can I declare numberofstudents globally, increment the counter each time through my while loop (in main), and use that variable in my calc_avg_gpa function?
2. Don't have any code for #2 yet. This is a requirement that I'm not sure where to start with what I have so far...I've found reference to the "free" function, but I'm not using pointers on this particular project (just arrays of a structure).
3. I tried something comparable to that, but got errors at compile time. "numberofkids" is a field within my structure, so when I use student.numberofkids in my comparison the compiler doesn't like it...something like "comparison cannot be made using type structure" is the error that was returned.
Apologize for not providing code...it's on my PC at home, and I'm not there right now.