Advertisement
Guest User

henry is gay

a guest
Oct 16th, 2017
364
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. /*=======================================================
  2. Programmer: Blake Gifford
  3. Email: bgifford@purdue.edu
  4. CNIT 105, InLab03
  5. Lab Session Time: Tuesday @9:30
  6. Program Description: Partially fill an array with up to 20 students’ GPAs by prompting the user in a loop.
  7. ==========================================================*/
  8. #define _CRT_SECURE_NO_WARNINGS
  9. #include <stdio.h>
  10. #include <conio.h>
  11. #include <math.h>
  12. #include <stdlib.h>
  13. #define SIZE 20
  14. //ONE
  15. int main()
  16. {
  17. float students[SIZE];
  18. float students2[SIZE];
  19. float gpa;
  20. int ctr;
  21. int ctr2 = 0;
  22. float num;
  23. float average;
  24. float sum = 0;
  25. float max;
  26. printf("Assignment06 - Output");
  27. printf("\n=======================\n\n");
  28. //TWO
  29. for (ctr = 0; ctr < SIZE; ctr++)
  30. {
  31. printf("Enter a GPA, -1 to stop the data entry: ");
  32. scanf("%f", &num);
  33. if (num == -1)
  34. {
  35. ctr2 = ctr;
  36. break;
  37. }
  38. students[ctr] = num;
  39. //average
  40. sum = sum + students[ctr];
  41. average = sum / (ctr + 1);
  42. max = students[0];
  43. //plus .2
  44. if (num + 0.2 >= 4.00)
  45. {
  46. students2[ctr] = 4.00;
  47. max = 4.00;
  48. }
  49. else if (num + 0.2 < 4.00)
  50. {
  51. students2[ctr] = num + 0.2;
  52. }
  53. }
  54. //THREE
  55. printf("\n\nNumber of GPA's entered = %d", ctr);
  56. //FOUR UNSURE OF THE PRINT
  57. printf("\n\nContents of the array:\n======================");
  58. for (ctr = 0; ctr < ctr2; ctr++)
  59. {
  60. printf("\n %.2f", students[ctr]);
  61. }
  62. //FIVE AVERAGE
  63. printf("\n\nAverage GPA = %.2f", average);
  64. //SIX ADD .2 TO ALL GPA
  65. printf("\n\nUpdated Array:\n=================");
  66. for (ctr = 0; ctr < ctr2; ctr++)
  67. {
  68. printf("\n %.2f", students2[ctr]);
  69. }
  70. for (ctr = 0; ctr < ctr2; ctr++)
  71. {
  72. if (students[ctr] > max)
  73. {
  74. max = students[ctr];
  75. }
  76. else if (students[ctr] <= max)
  77. {
  78. max = max;
  79. }
  80. }
  81. printf("\n\nMaximum GPA = %.2f", max);
  82.  
  83. _getch();
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement