fork download
  1. //NAME: LIM JING YEE
  2. //IC: 060502070477
  3. //DATE: 14-3-25
  4. //COURSEWORK B1: CONDITIONAL STATEMENTS
  5.  
  6. #include <stdio.h>
  7. int main() {
  8. char grade;
  9. float points;
  10.  
  11. // Display grading table
  12. printf("---------------------------------------\n");
  13. printf("| Grade | A | B | C | D | E |\n");
  14. printf("---------------------------------------\n");
  15. printf("| Points| 4 | 3 | 2 | 1 | 0 |\n");
  16. printf("---------------------------------------\n");
  17.  
  18. // Read input
  19. printf("Enter grade of the subject : ");
  20. scanf(" %c", &grade); // Space skips whitespace
  21.  
  22. // Show input
  23. printf("%c\n", grade);
  24.  
  25.  
  26. // Determine points
  27. switch (grade) {
  28. case 'A':
  29. case 'a':
  30. points = 4.00;
  31. break;
  32. case 'B':
  33. case 'b':
  34. points = 3.00;
  35. break;
  36. case 'C':
  37. case 'c':
  38. points = 2.00;
  39. break;
  40. case 'D':
  41. case 'd':
  42. points = 1.00;
  43. break;
  44. case 'E':
  45. case 'e':
  46. points = 0.00;
  47. break;
  48. default:
  49. printf("Invalid grade entered.\n");
  50. return 1; // Terminate on error
  51. }
  52.  
  53. // Output result
  54. printf("\nPoints obtain : %.2f\n", points);
  55. return 0;
  56. }
  57.  
Success #stdin #stdout 0.01s 5288KB
stdin
C
stdout
---------------------------------------
| Grade | A | B | C | D | E |
---------------------------------------
| Points| 4 | 3 | 2 | 1 | 0 |
---------------------------------------
Enter grade of the subject : C

Points obtain : 2.00