Link to home
Start Free TrialLog in
Avatar of ronron10
ronron10

asked on

math logic using structures

i am trying to write a function that will add all the interger values in an array with the integer values of other arrays, placing the total in its own variable all within the same structure.
Avatar of MatthewL
MatthewL

Hi ronron10;

I'm not sure if I understand the problem clearly.  Is this the structure you had in mind?
Or is there a second int array in the structure to hold the sums?

Matt
Forgot to include the structure!

typedef struct      {      int numbers[20];
                  int size;
             } intArray;

Matt
ASKER CERTIFIED SOLUTION
Avatar of alexo
alexo
Flag of Antarctica image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ronron10

ASKER

struct students
{
      char name[25];
      int test[6];
      int assignment[10];
      int total_points;
      int final_exam;

}class_[25];
i'm trying to put the sum of test[], assignment[],and final_exam into total_points
Avatar of ozo
Is this question a test, assignment, or final_exam?
Is this what you mean (assuming you have an int i)

student.total_points = 0;
for (i = 0; i < 6; i++) {
  student.total_point += student.test[i];
}
for (i = 0; i < 10; i++) {
  student.total_point += student.assignment[i];
}
student.total_point += student.final_exam;

It's not really that hard... did you try it yourself first?

Did you try it first RONSLOW?:)  Is this what you mean

class_[j].total_points = 0;

ronron10, if you can tell us what you tried, and what difficulties you had,
it may be easier for us to understand what help you need.
just showed him how to accumulate a single student.  Don't want to do TOO much for him as it does seem like homework.  But if you want to be more specific...

for (j = 0; j < 25; j++) {
  class_[j].total_points = 0;
  for (i = 0; i < 6; i++) {
    class_[j].total_point += class_[j].test[i];
  }
  for (i = 0; i < 10; i++) {
    class_[j].total_point += class_[j].assignment[i];
  }
  class_[j].total_point += class_[j].final_exam;
}

this assumes you have int i,j;

Of course, you'd need to wrap this up into a function and pass a students[] array to it