#include <stdio.h>
#include <ctype.h> /* for the toupper function */
int main ()
{
char answer [80]; /* string to hold user response */
char grade; /* your exam grade */
/* Ask student for their exam grade */
printf ("\n Enter your exam grade: ");
/* convert character to upper case using the C library function toupper */
/* Skip a few lines */
/* Student Self Service based on their grade */
switch ( grade )
{
case 'A':
printf ("\nExcellent Job: Grade is an A \n"); break;
case 'B':
printf ("\nGood Job: Grade is a B \n"); printf ("\nWould you like an A? (y/n): ");
/* Come on, answer yes, professor needs a new electronic toy */
if ( answer [0] == 'y' || answer [0] == 'Y' )
{
/* All right, a customer */
printf ("\n Make check payable to Tim Niesen for $200 \n"); printf ("... a small price to pay for your education \n"); }
break;
case 'C':
printf ("\nFair Job: Grade is a C \n"); printf ("Would you like an A? (y/n): "); scanf ("%s", answer
); /* we'll discuss strings next week, but its a series of characters */
/* time to make some real money, my favorite students */
if ( answer [0] == 'y' || answer [0] == 'Y' )
{
printf ("\n Make check payable to Tim Niesen for $600 \n"); printf ("... an excellent price to pay for your education \n"); }
else
{
printf ("\nWould you like an B? (y/n): ");
if ( answer [0] == 'y' || answer [0] == 'Y' )
{
printf ("\nMake check payable to Tim Niesen for $400 \n"); printf ("... a great price to pay for your education \n"); } /* if */
} /* else */
break;
case 'D':
printf ("\n Poor Job: Grade is a D \n"); printf ("... You're beyond a bribe to get a better grade \n"); break;
case 'F':
printf ("\n Looks like you Failed. Grade is a F \n"); break;
default: /* if it gets here, not a valid grade */
printf ("\n Invalid/Incomplete Grade ... can not process ...\n"); break; /* optional, but recommended */
} /* switch */
return (0);
} /* main */
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjdHlwZS5oPiAvKiBmb3IgdGhlIHRvdXBwZXIgZnVuY3Rpb24gKi8KCmludCBtYWluICgpCnsKCiAgICBjaGFyIGFuc3dlciBbODBdOyAgLyogc3RyaW5nIHRvIGhvbGQgdXNlciByZXNwb25zZSAqLwogICAgY2hhciBncmFkZTsgICAgICAgIC8qIHlvdXIgZXhhbSB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BjaGVjayBwYXlhYmxlIHRvIFRpbSBOaWVzZW4gZm9yICQyMDAgXG4iKTsKICAgICAgICAgICAgICAgIHByaW50ZiAoIi4uLiBhIHNtYWxsIHByaWNlIHRvIHBheSBmb3IgeW91ciBlZHVjYXRpb24gXG4iKTsKICAgICAgICAgICAgfQoKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0MnOgoKICAgICAgICAgICAgcHJpbnRmICgiXG5GYWlyIEpvYjogR3JhZGUgaXMgYSBDIFxuIik7CiAgICAgICAgICAgIHByaW50ZiAoIldvdWxkIHlvdSBsaWtlIGFuIEE/ICh5L24pOiAiKTsKICAgICAgICAgICAgc2NhbmYgKCIlcyIsIGFuc3dlcik7ICAvKiB3ZSdsbCBkaXNjdXNzIHN0cmluZ3MgbmV4dCB3ZWVrLCBidXQgaXRzIGEgc2VyaWVzIG9mIGNoYXJhY3RlcnMgKi8KCiAgICAgICAgICAgIC8qIHRpbWUgdG8gbWFrZSBzb21lIHJlYWwgbW9uZXksIG15IGZhdm9yaXRlIHN0dWRlbnRzICovCiAgICAgICAgICAgIGlmICggYW5zd2VyIFswXSA9PSAneScgfHwgYW5zd2VyIFswXSA9PSAnWScgKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBwcmludGYgKCJcbiBNYWtlIGNoZWNrIHBheWFibGUgdG8gVGltIE5pZXNlbiBmb3IgJDYwMCBcbiIpOwogICAgICAgICAgICAgICAgcHJpbnRmICgiLi4uIGFuIGV4Y2VsbGVudCBwcmljZSB0byBwYXkgZm9yIHlvdXIgZWR1Y2F0aW9uIFxuIik7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgZWxzZSAKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgcHJpbnRmICgiXG5Xb3VsZCB5b3UgbGlrZSBhbiBCPyAoeS9uKTogIik7CiAgICAgICAgICAgICAgICBzY2FuZiAoIiVzIiwgYW5zd2VyKTsKCiAgICAgICAgICAgICAgICBpZiAoIGFuc3dlciBbMF0gPT0gICd5JyAgfHwgIGFuc3dlciBbMF0gPT0gICdZJyApCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICBwcmludGYgKCJcbk1ha2UgY2hlY2sgcGF5YWJsZSB0byBUaW0gTmllc2VuIGZvciAkNDAwIFxuIik7CiAgICAgICAgICAgICAgICAgICBwcmludGYgKCIuLi4gYSBncmVhdCBwcmljZSB0byBwYXkgZm9yIHlvdXIgZWR1Y2F0aW9uIFxuIik7CiAgICAgICAgICAgICAgICB9IC8qIGlmICovCiAgICAgICAgICAgIH0gLyogZWxzZSAqLwoKICAgICAgICAgICAgYnJlYWs7CgogICAgICAgIGNhc2UgJ0QnOgoKICAgICAgICAgICAgcHJpbnRmICgiXG4gUG9vciBKb2I6IEdyYWRlIGlzIGEgRCBcbiIpOwogICAgICAgICAgICBwcmludGYgKCIuLi4gWW91J3JlIGJleW9uZCBhIGJyaWJlIHRvIGdldCBhIGJldHRlciBncmFkZSBcbiIpOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgY2FzZSAnRic6CgogICAgICAgICAgICBwcmludGYgKCJcbiBMb29rcyBsaWtlIHlvdSBGYWlsZWQuIEdyYWRlIGlzIGEgRiBcbiIpOwogICAgICAgICAgICBicmVhazsKCiAgICAgICAgZGVmYXVsdDogLyogaWYgaXQgZ2V0cyBoZXJlLCBub3QgYSB2YWxpZCBncmFkZSAqLwoKICAgICAgICAgICAgcHJpbnRmICgiXG4gSW52YWxpZC9JbmNvbXBsZXRlIEdyYWRlIC4uLiBjYW4gbm90IHByb2Nlc3MgLi4uXG4iKTsKICAgICAgICAgICAgYnJlYWs7ICAvKiBvcHRpb25hbCwgYnV0IHJlY29tbWVuZGVkICovCgogICAgfSAvKiBzd2l0Y2ggKi8KCiAgICByZXR1cm4gKDApOwoKfSAvKiBtYWluICovCg==