About Me

Friday, October 10, 2008


This is a program that will ask the user a value for the radius R. Then present a menu to the user with choices [a] radius, [b] circumference, [c] area of circle. If the user inputs letter 'a' or 'A', it will print at the center of the screen the radius. If the user presses letter 'b' or 'B', the circumference will be shown at the center of the screen. And if 'c' or 'C' is pressed, the area of the circle is shown also in the center of the screen. The the program terminates. (note: I'm using 'switch stat
ement')




CODES:

#include

#include

/* EXERCISE 6-1 */
main()

{
char select;
float radius;
const float pi=3.14159;
again:
clrscr();
printf("Please enter a value for radius: ");
scanf("%f", &radius);
printf("\n\nMenu Options (Circle): \n");
printf("[a] radius \n");
printf("[b] circumference \n");
printf("[c] area \n");
select=getche();
switch(select)
{
case 'a':
case 'A':
gotoxy(34,12);
printf("Radius: %.2f",radius);
break;
case 'b':
case 'B':
gotoxy(32,12);
printf("Circumference is: %.2f",2*pi*radius);
break;
case 'c':
case 'C':
gotoxy(34,12);
printf("Area is: %.2f", pi*radius*radius);
break;
default:
printf("\n\nInvalid Character!");
printf("Please try again!");
goto again;
}
getch();
}




OUTPUT:




No comments: