hey everyone. School is finally over (heck yes!) and next semester I'm moving onto C++, kinda nerve recking. I don't have a good C backround yet. So I'm working on some problems from our text book over the holidays. (If anyone has some interesting problems/programs that I could practice they would be appreciated) Anyway, I'm working on a problem now that finds 5 students grades I was wondering if you could help me out with it.

Program that prints the average for each student in the class(I know I'm going to use some arrays and pointers... I just don't know how to set it up)

"A"=4
"B"=3
"C"=2
"D"=1
"F"=0

Number of students is 5(just picked a number)
each student has 4 grades
the user is going to input all the information for each student
calculate grade average
then output information of student(name, id) and the students grade average

Any help would be appreciated... or I'll be stuck on it all break... lol ><

Some ideas:

#include <stdio.h>

struct student
{
   int     id;
   char    name [ 32 ];
   double  grade [ 4 ];
};

void show(struct student *student)
{
   static const char letter[] = "FDCBA";
   size_t i;
   double sum = 0;
   for ( i = 0; i < sizeof student->grade / sizeof *student->grade; ++i )
   {
      sum += student->grade[i];
   }
   sum /= i;
   printf("%3d %-31s %c\n", student->id, student->name, letter [ (int)sum ] );
}

int main(void)
{
   struct student coder[] =
   {
      { 123, "Slim Pickens",  {1,2,3,4} },
      { 125, "Guy Wire",      {2,2,3,2} },
      { 128, "MaeFlowers",    {0,1,1,1} },
      { 132, "June Meadows",  {2,1,1,2} },
      { 121, "April Showers", {3,3,3,3} },
      { 119, "Les Ismoore",   {1,2,3,4} },
      { 137, "Harry Legg",    {3,2,3,3} },
      { 142, "Sara Bellum",   {4,2,3,4} },
      { 159, "Pete Moss",     {4,4,4,4} },
   };
   size_t i;
   for ( i = 0; i < sizeof coder / sizeof *coder; ++i )
   {
      show(&coder[i]);
   }
   return 0;
}

/* my output
123 Slim Pickens                    C
125 Guy Wire                        C
128 MaeFlowers                      F
132 June Meadows                    D
121 April Showers                   B
119 Les Ismoore                     C
137 Harry Legg                      C
142 Sara Bellum                     B
159 Pete Moss                       A
*/
This article has been dead for over six months. Start a new discussion instead.