Guest User

Untitled

a guest
Nov 24th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. /****************************************************************************
  2. * array2.c
  3. *
  4. * Computer Science 50
  5. * David J. Malan
  6. *
  7. * Computes a student's average across 2 quizzes.
  8. *
  9. * Demonstrates C's math library.
  10. ***************************************************************************/
  11.  
  12. #include <cs50.h>
  13. #include <math.h>
  14. #include <stdio.h>
  15.  
  16.  
  17. // number of quizzes per term
  18. #define QUIZZES 2
  19.  
  20.  
  21. int
  22. main(void)
  23. {
  24. float grades[QUIZZES], sum;
  25. int average, i;
  26.  
  27. // ask user for grades
  28. printf("\nWhat were your quiz scores?\n\n");
  29. for (i = 0; i < QUIZZES; i++)
  30. {
  31. printf("Quiz #%d of %d: ", i+1, QUIZZES);
  32. grades[i] = GetFloat();
  33. }
  34.  
  35. // compute average
  36. sum = 0;
  37. for (i = 0; i < QUIZZES; i++)
  38. sum += grades[i];
  39. average = (int) round(sum / QUIZZES);
  40.  
  41. // report average
  42. printf("\nYour average is: %d\n\n", average);
  43. }
Add Comment
Please, Sign In to add comment