fork download
  1. #include <stdio.h>
  2. int main ()
  3. {
  4. char answer[20]; /* user response to yes or no question */
  5. int score; /* test score */
  6. printf ("\nEnter a score: ");
  7. scanf ("%i", &score);
  8. /* Process Grade and Options based on Score */
  9. if (score < 0 || score > 100)
  10. printf ("\nError, Invalid Grade \n");
  11. else if (score >= 90) /* 90-100 */
  12. {
  13. /* you need these students, but can't make any money from them :) */
  14. printf ("\nExcellent Job: Grade is an A \n");
  15. } /* 90 - 100 */
  16. else if (score >= 80) /* 80-89 */
  17. {
  18. printf ("\nGood Job: Grade is a B \n");
  19. printf ("Would you like an A? (y/n): ");
  20. scanf ("%s", answer);
  21. /* Come on, answer yes, professor needs a new electronic toy */
  22. if (answer[0] == 'y' || answer[0] == 'Y')
  23. {
  24. /* All right, a customer */
  25. printf ("\nMake check payable to Tim Niesen for $200\n");
  26. printf ("... a small price to pay for your education \n");
  27. }
  28. } /* 80 - 89 */
  29. else if (score >= 70) /* 70 - 79 */
  30. {
  31. printf ("\nFair Job: Grade is a C \n");
  32. printf ("Would you like an A? (y/n): ");
  33. scanf ("%s", answer); /* The & not needed with Arrays, will discuss
  34. this in the future */
  35. /* time to make some real money, my favorite students */
  36. if (answer[0] == 'y' || answer[0] == 'Y')
  37. {
  38. printf ("\nMake check payable to Tim Niesen for $600 \n");
  39. printf ("... an excellent price to pay for your education \n");
  40. }
  41. else /* maybe the student will pay to get a B ? */
  42. {
  43. printf ("\nWould you like an B? (y/n): ");
  44. scanf ("%s", answer);
  45. if (answer[0] == 'y' || answer[0] == 'Y')
  46. {
  47. printf ("\nMake check payable to Tim Niesen for $400 \n");
  48. printf ("... a great price to pay for your education \n");
  49. }
  50. }
  51. } /* 70 - 79 */
  52. else if (score >= 60) /* 60 - 69 */
  53. {
  54. /* just can't make any money here, would not be right */
  55. printf ("\nPoor Job: Grade is a D \n");
  56. printf ("... You're beyond a bribe to get a better grade \n");
  57. } /* 60 - 69 */
  58. else /* < 60 */
  59. {
  60. printf ("\nYou Failed: Grade is an F :(\n");
  61. }
  62. return (0); /* success */
  63. } /* end main */
Success #stdin #stdout 0s 5456KB
stdin
73
y
stdout
Enter a score: 
Fair Job: Grade is a C 
Would you like an A? (y/n): 
Make check payable to Tim Niesen for $600 
... an excellent price to pay for your education