C - Write program to check y Y n N as your input, uppercase and lowercase

Requirements

Write program to check y Y n N as your input, uppercase and lowercase

Hint

Convert to upper case to save two if statements

Demo

#include <stdio.h>
#include <ctype.h>

int main()/* w  w w .  j a  v  a2  s  . co m*/
{
    char answer;

    printf("Would you like to blow up the moon? ");
    scanf("%c",&answer);
    answer = toupper(answer);
    if(answer=='Y')
        puts("BOOM!");
    else if(answer=='N')
        puts("The moon is safe");
    else
        puts("Indecision can be fatal!");
    return(0);
}

Result

Related Exercise