fork download
  1. #include <stdio.h>
  2. #include <ctype.h> /* for the toupper function */
  3.  
  4. int main ()
  5. {
  6.  
  7. char answer [80]; /* string to hold user response */
  8. char grade; /* your exam grade */
  9.  
  10. /* Ask student for their exam grade */
  11. printf ("\n Enter your exam grade: ");
  12. grade = getchar();
  13.  
  14. /* convert character to upper case using the C library function toupper */
  15. grade = toupper ( grade );
  16.  
  17. /* Skip a few lines */
  18. printf ("\n\n");
  19.  
  20. /* Student Self Service based on their grade */
  21. switch ( grade )
  22. {
  23.  
  24. case 'A':
  25.  
  26. printf ("\nExcellent Job: Grade is an A \n");
  27. break;
  28.  
  29. case 'B':
  30.  
  31. printf ("\nGood Job: Grade is a B \n");
  32. printf ("\nWould you like an A? (y/n): ");
  33. scanf ("%s", answer);
  34.  
  35. /* Come on, answer yes, professor needs a new electronic toy */
  36. if ( answer [0] == 'y' || answer [0] == 'Y' )
  37. {
  38. /* All right, a customer */
  39. printf ("\n Make check payable to Tim Niesen for $200 \n");
  40. printf ("... a small price to pay for your education \n");
  41. }
  42.  
  43. break;
  44.  
  45. case 'C':
  46.  
  47. printf ("\nFair Job: Grade is a C \n");
  48. printf ("Would you like an A? (y/n): ");
  49. scanf ("%s", answer); /* we'll discuss strings next week, but its a series of characters */
  50.  
  51. /* time to make some real money, my favorite students */
  52. if ( answer [0] == 'y' || answer [0] == 'Y' )
  53. {
  54. printf ("\n Make check payable to Tim Niesen for $600 \n");
  55. printf ("... an excellent price to pay for your education \n");
  56. }
  57. else
  58. {
  59. printf ("\nWould you like an B? (y/n): ");
  60. scanf ("%s", answer);
  61.  
  62. if ( answer [0] == 'y' || answer [0] == 'Y' )
  63. {
  64. printf ("\nMake check payable to Tim Niesen for $400 \n");
  65. printf ("... a great price to pay for your education \n");
  66. } /* if */
  67. } /* else */
  68.  
  69. break;
  70.  
  71. case 'D':
  72.  
  73. printf ("\n Poor Job: Grade is a D \n");
  74. printf ("... You're beyond a bribe to get a better grade \n");
  75. break;
  76.  
  77. case 'F':
  78.  
  79. printf ("\n Looks like you Failed. Grade is a F \n");
  80. break;
  81.  
  82. default: /* if it gets here, not a valid grade */
  83.  
  84. printf ("\n Invalid/Incomplete Grade ... can not process ...\n");
  85. break; /* optional, but recommended */
  86.  
  87. } /* switch */
  88.  
  89. return (0);
  90.  
  91. } /* main */
  92.  
Success #stdin #stdout 0s 5304KB
stdin
A
stdout
 Enter your exam grade: 


Excellent Job: Grade is an A