Boolean data type

Using bool.

Assign isTeenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign isTeenager with false.

#include <stdio.h>
#include <stdbool.h>

int main(void) {
 bool isTeenager;
 int kidAge;

kidAge = 13;

if ((kidAge >= 13)&&(kidAge <= 19)) {
 isTeenager = true;
}


 if (isTeenager) {
 printf("Teen\n");
 }
 else {
 printf("Not teen\n");
 }

return 0;
}

 

Bool in branching statements.

 Write an if-else statement to describe an object. Print “Balloon” if isBalloon is true and isRed is false. Print “Red balloon” if isBalloon and isRed are both true. Print “Not a balloon” otherwise. End with newline. (Notes)
#include <stdio.h>
#include <stdbool.h>

int main(void) {
 bool isRed;
 bool isBalloon;

isRed = false;
 isBalloon = false;


 if ((isBalloon) && (!isRed)){

printf("Balloon\n");}

else if(isBalloon && isRed){printf("Red balloon\n");}

else {printf("Not a balloon\n");}

return 0;
}