Solution for Exercise 8-18

ex0818

#include <stdio.h>

int main()
{
    char code;

    printf("Enter the error letter (A, B, C): ");
    scanf("%c",&code);

    switch(code)
    {
        case 'A':
            puts("Drive Fault, not your fault.");
            break;
        case 'B':
            puts("Illegal format, call a lawyer.");
            break;
        case 'C':
            puts("Bad filename, spank it.");
            break;
        default:
            puts("That's not A, B, or C");
    }
    return(0);
}

Notes

* It's okay if you used getchar() in Line 8 instead of scanf(). Both functions do essentially the same thing for single character input.

* It's important that the characters being compared are specified in single quotes, as shown at Lines 12, 15, and 18.

* I hope you remembered to change the text from Line 22!