arthurtung

Untitled

Jul 15th, 2016
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 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 pct;
  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]={0};
  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. for (int i=0; i<list; i++)
  51. {
  52. scorearray[i]=getUser(score);
  53. }
  54. }
  55. else if (3==option)
  56. {
  57.  
  58. if (score_ent)
  59. {
  60. printf("Your score is : %2.2f\n", getAvg(list, scorearray));
  61. }
  62.  
  63. else
  64. {
  65. printf("Please use the menu to enter your score first.\n");
  66. }
  67. }
  68. else if (4==option)
  69. {
  70. if (score_ent && name_ent)
  71. {
  72. printf("Hello %s, according to your test scores of, ", name);
  73. for (int i=0; i<list; i++)
  74. {
  75. printf("%d", scorearray[i]);
  76. }
  77. printf("the average score is %2.2f with a letter grade of %c.\n", getAvg(list, scorearray), getGrade(pct,grade));
  78. }
  79. else
  80. {
  81. printf("Please use the menu to enter your name and score first.\n");
  82. }
  83. }
  84.  
  85. }while (option !=5);
  86. }
  87.  
  88. float getUser( float score)
  89. {
  90. printf("What was the score of this exam?");
  91. scanf("%f", &score);
  92. return score;
  93.  
  94. }
  95. float getAvg(int list, float *scorearray)
  96. {
  97. float ave=0;
  98. for (int i=0; i<list; i++)
  99. {
  100. ave+=scorearray[i]/list;
  101. }
  102. return ave;
  103. }
  104. float calculatepercent(float score, float max)
  105. {
  106. float pt = score / max;
  107. return pt;
  108. }
  109. char getGrade(float pt, char grade)
  110. {
  111. if (pt >= 90)
  112. {
  113. grade = 'A';
  114. }
  115. else if (pt >= 80)
  116. {
  117. grade = 'B';
  118. }
  119. else if (pt >= 70)
  120. {
  121. grade = 'C';
  122. }
  123. else if (pt >= 60)
  124. {
  125. grade = 'D';
  126. }
  127. else
  128. {
  129. grade = 'F';
  130. }
  131. return grade;
  132. }
  133. void printline(char line, int count)
  134. {
  135. for (int i=0; i<count; i++)
  136. {
  137. printf("%c", line);
  138. }
  139. printf("\n");
  140. }
Add Comment
Please, Sign In to add comment