Advertisement
arthurtung

Untitled

Jul 15th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void enableFlushAfterPrintf()
  4. {
  5. setvbuf(stdout, 0, _IONBF, 0);
  6. setvbuf(stdin, 0, _IONBF, 0);
  7. }
  8. float getAvg(int list, float *scorearray);
  9. float getUser( float score);
  10. float calculatepercent(float score, float max);
  11. char getGrade(float pt, char grade);
  12. void printline(char line,int count);
  13.  
  14. int main()
  15. {
  16. enableFlushAfterPrintf();
  17. int option;
  18. int score;
  19. float scorearray[100]={0};
  20. int list;
  21. float ave;
  22. char grade;
  23. bool name_ent=false;
  24. bool score_ent=false;
  25. int sum;
  26. do
  27. {
  28. printline('A', 10);
  29. printf("1. Enter name\n");
  30. printf("2. Enter exam scores:\n");
  31. printf("3. Display average exam scores\n");
  32. printf("4. Display summary\n");
  33. printf("5. Quit\n");
  34.  
  35. char name[32];
  36.  
  37. scanf("%i", &option);
  38.  
  39. if (1 == option)
  40. {
  41. name_ent = true;
  42. printf("Enter your name: ");
  43. scanf("%s", name);
  44. }
  45. else if (2 == option)
  46. {
  47. score_ent=true;
  48. printf("How many scores are there");
  49. scanf("%i", &list);
  50. if (list>100)
  51. {
  52. printf("Please enter a value of 100 or less\n");
  53. }
  54. else
  55. {
  56.  
  57.  
  58. for (int i=0; i<list; i++)
  59. {
  60. scorearray[i]=getUser(score);
  61. }
  62. }
  63. }
  64. else if (3==option)
  65. {
  66.  
  67. if (score_ent)
  68. {
  69. printf("Your score is : %2.2f\n", getAvg(list, scorearray));
  70. }
  71.  
  72. else
  73. {
  74. printf("Please use the menu to enter your score first.\n");
  75. }
  76. }
  77. else if (4==option)
  78. {
  79. if (score_ent && name_ent)
  80. {
  81. printf("Hello %s, according to your test scores of ", name);
  82. for (int i=0; i<list; i++)
  83. {
  84. printf("%0.0f,", scorearray[i]);
  85. }
  86. printf("the average score is %2.2f with a letter grade of %c.\n", getAvg(list, scorearray), getGrade(ave,grade));
  87. }
  88. else
  89. {
  90. printf("Please use the menu to enter your name and score first.\n");
  91. }
  92. }
  93.  
  94. }while (option !=5);
  95. }
  96.  
  97. float getUser( float score)
  98. {
  99. printf("What was the score of this exam?");
  100. scanf("%f", &score);
  101. return score;
  102.  
  103. }
  104. float getAvg(int list, float *scorearray)
  105. {
  106. float ave=0;
  107. for (int i=0; i<list; i++)
  108. {
  109. ave+=scorearray[i]/list;
  110. }
  111. return ave;
  112. }
  113. float calculatepercent(float score, float max)
  114. {
  115. float pt = score / max;
  116. return pt;
  117. }
  118. char getGrade(float pt, char grade)
  119. {
  120. if (pt >= 90)
  121. {
  122. grade = 'A';
  123. }
  124. else if (pt >= 80)
  125. {
  126. grade = 'B';
  127. }
  128. else if (pt >= 70)
  129. {
  130. grade = 'C';
  131. }
  132. else if (pt >= 60)
  133. {
  134. grade = 'D';
  135. }
  136. else
  137. {
  138. grade = 'F';
  139. }
  140. return grade;
  141. }
  142. void printline(char line, int count)
  143. {
  144. for (int i=0; i<count; i++)
  145. {
  146. printf("%c", line);
  147. }
  148. printf("\n");
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement