Solution for Exercise 13-5
ex1305
#include <stdio.h>
#include <ctype.h>
int main()
{
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);
}
Output
Would you like to blow up the moon? 8
Indecision can be fatal!
Notes
* The obvious solution is to construct an if-else if-else structure. Even so, you'd get points if you constructed a switch-case structure instead. Either method solves the problem.
* If you'd like the practice, construct a switch-case solution.
* Single characters literals in C are enclosed in single quotes.
Copyright © 1997-2025 by QPBC.
All rights reserved
