HP C A.06.05 Reference Manual
Statements
if
Chapter 6172
printf("You have %d years before you're an adult.\n",
of_age);
} /* end else */
printf("\n");
printf("This part will help you decide whether to jog \
today.\n");
printf("What is the weather like?\n");
printf(" raining = r\n");
printf(" cold = c\n");
printf(" muggy = m\n");
printf(" hot = h\n");
printf(" nice = n\n");
printf("Enter one of the choices: ");
fflush(stdin);
scanf("\n%c", &answer);
/* This if statement is an example of the third form (see
* "Description" section. */
if (answer == 'r')
printf("It's too wet to jog today. Don't bother.\n");
else if (answer == 'c')
printf("You'll freeze if you jog today. Stay indoors.\n");
else if (answer == 'm')
printf("It's no fun to run in high humidity. Skip it.\n");
else if (answer == 'h')
printf("You'll die of the heat if you try to jog today. \
So don't.\n");
else if (answer == 'n')
printf("You don't have any excuses. You'd better go \
run.\n");
else
printf("You didn't give a valid answer.\n");
}
If you execute this program, you get the following output:
Enter an age: 15
You have 3 years before you're an adult.
This part will help you decide whether to jog today.
What is the weather like?
raining = r
cold = c
muggy = m