Getting a Grade Average

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2004
Posts: 11
Reputation: tyalangan is an unknown quantity at this point 
Solved Threads: 0
tyalangan tyalangan is offline Offline
Newbie Poster

Getting a Grade Average

 
0
  #1
Dec 9th, 2004
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 ><
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,413
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 248
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Getting a Grade Average

 
0
  #2
Dec 9th, 2004
Some ideas:
  1. #include <stdio.h>
  2.  
  3. struct student
  4. {
  5. int id;
  6. char name [ 32 ];
  7. double grade [ 4 ];
  8. };
  9.  
  10. void show(struct student *student)
  11. {
  12. static const char letter[] = "FDCBA";
  13. size_t i;
  14. double sum = 0;
  15. for ( i = 0; i < sizeof student->grade / sizeof *student->grade; ++i )
  16. {
  17. sum += student->grade[i];
  18. }
  19. sum /= i;
  20. printf("%3d %-31s %c\n", student->id, student->name, letter [ (int)sum ] );
  21. }
  22.  
  23. int main(void)
  24. {
  25. struct student coder[] =
  26. {
  27. { 123, "Slim Pickens", {1,2,3,4} },
  28. { 125, "Guy Wire", {2,2,3,2} },
  29. { 128, "MaeFlowers", {0,1,1,1} },
  30. { 132, "June Meadows", {2,1,1,2} },
  31. { 121, "April Showers", {3,3,3,3} },
  32. { 119, "Les Ismoore", {1,2,3,4} },
  33. { 137, "Harry Legg", {3,2,3,3} },
  34. { 142, "Sara Bellum", {4,2,3,4} },
  35. { 159, "Pete Moss", {4,4,4,4} },
  36. };
  37. size_t i;
  38. for ( i = 0; i < sizeof coder / sizeof *coder; ++i )
  39. {
  40. show(&coder[i]);
  41. }
  42. return 0;
  43. }
  44.  
  45. /* my output
  46. 123 Slim Pickens C
  47. 125 Guy Wire C
  48. 128 MaeFlowers F
  49. 132 June Meadows D
  50. 121 April Showers B
  51. 119 Les Ismoore C
  52. 137 Harry Legg C
  53. 142 Sara Bellum B
  54. 159 Pete Moss A
  55. */
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC