fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define P 50
  6. #define H3 65
  7. #define H2b 70
  8. #define H2a 75
  9. #define H1 80
  10. #define MAX 10
  11.  
  12. typedef char name_t[MAX];
  13. typedef struct {
  14. name_t name;
  15. double mark;
  16. double outof;
  17. double weight;
  18. double total;
  19. } assesment_t;
  20.  
  21.  
  22. int main(int argc, char **argv){
  23. assesment_t Subject[MAX];
  24. /*---------------------------------------------------------------------------*/
  25. printf("\n\nEnter information in this order separated by a space\n");
  26. printf("When all info entered, press enter\n");
  27. printf("(Include exam but enter the Mark bit as 0):\n");
  28. printf("Name Mark OutOf Weight\n\n");
  29. /*---------------------------------------------------------------------------*/
  30. int i, n;
  31. double total = 0;
  32. /*---------------------------------------------------------------------------*/
  33. for(i = 0;(scanf("%s %lf %lf %lf", Subject[i].name,&Subject[i].mark,&Subject[i].outof,&Subject[i].weight)) == 4;i++) {
  34.  
  35. if(i == 0) {
  36. printf("Name\tMark\tOut of\tWeight\tTotal");
  37. }
  38.  
  39. Subject[i].total = ( (Subject[i].mark/Subject[i].outof) * Subject[i].weight );
  40.  
  41. printf("\n%s\t%2.1lf\t%2.1lf\t%2.2lf\t%2.2lf", Subject[i].name, Subject[i].mark,
  42. Subject[i].outof, Subject[i].weight, Subject[i].total);
  43. }
  44. /*---------------------------------------------------------------------------*/
  45. n = i;
  46. for( i = 0; i < n; i++) {
  47. total += Subject[i].total;
  48. }
  49. printf("\nTotal: %3.2lf\n\n", total);
  50. /*---------------------------------------------------------------------------*/
  51. double grade, result;
  52. for( grade = 23; grade <= 60; grade++) {
  53. result = (grade / Subject[i-1].outof) * Subject[i-1].weight;
  54. if(total + result > P && (total + result - 1) < P)
  55. printf("minimum of %2.0lf is needed for FAIL\n", grade);
  56. else if(total + result > H3 && (total + result - 1) < H3)
  57. printf("minimum of %2.0lf is needed for P\n", grade);
  58. else if(total + result > H2b && (total + result - 1) < H2b)
  59. printf("minimum of %2.0lf is needed for H3\n", grade);
  60. else if(total + result > H2a && (total + result - 1) < H2a)
  61. printf("minimum of %2.0lf is needed for H2b\n", grade);
  62. else if(total + result > H1 && (total + result - 1) < H1)
  63. printf("minimum of %2.0lf is needed for H2a\n", grade);
  64. else if(total + result > H1 && (total + result - 1) < H1)
  65. printf("minimum of %2.0lf is needed for H1\n", grade);
  66. else
  67. ;
  68. }
  69. /*---------------------------------------------------------------------------*/
  70. return 0;
  71. }
Success #stdin #stdout 0s 2252KB
stdin
MST 5 10 10
ProjA 9 10 15
ProjB 17.5 20 15
Exam 0 60 60
stdout

Enter information in this order separated by a space
When all info entered, press enter
(Include exam but enter the Mark bit as 0):
Name    Mark    OutOf   Weight

Name	Mark	Out of	Weight	Total
MST	5.0	10.0	10.00	5.00
ProjA	9.0	10.0	15.00	13.50
ProjB	17.5	20.0	15.00	13.12
Exam	0.0	60.0	60.00	0.00
Total: 31.62

minimum of 34 is needed for P
minimum of 39 is needed for H3
minimum of 44 is needed for H2b
minimum of 49 is needed for H2a