HP C A.06.05 Reference Manual
Statements
goto
Chapter 6 167
char answer;
extern void something_different(void);
circles:
printf("Enter the circle's radius: ");
scanf("%f", &radius);
cir = 2 * PI * radius;
area = PI * (radius * radius);
printf("The circle's circumference is: %6.3f\n", cir);
printf("Its area is: %6.3f\n", area);
printf("\nAgain? y or n: ");
fflush(stdin);
scanf("%c", &answer);
if (answer == 'y' || answer == 'Y')
goto circles;
else {
printf("Do you want to try something different? ");
fflush(stdin);
scanf("%c", &answer);
if (answer == 'y' || answer == 'Y')
/* goto different; WRONG! This label is in */
/* another block. */
something_different();
} /* end else */
}
void something_different(void)
{
different:
printf("Hello. This is something different.\n");
}
If you execute this program, you get the following output:
Enter the circle's radius: 3.5
The circle's circumference is: 21.991
Its area is: 38.484
Again? y or n: y
Enter the circle's radius: 6.1
The circle's circumference is: 38.327
Its area is: 116.899