### programming project help c language 7.30 (Calculating Circle Circumference, Circle Area or Sphere Volume Using Function Pointers)

Using the techniques you learned in Fig. 7.28, create a text-based , menu-driven program that allows
the user to choose whether to calculate the circumference of a circle, the area of a circle or the
volume of a sphere.

The program should then input a radius from the user, perform the appropriate calculation and
display the result. Use an array of function pointers in which each pointer represents a function
that returns void and receives a double parameter . The corresponding functions should each display
messages indicating which calculation was performed, the value of the radius and the result of the
calculation.

For the purposes of this exercise, assume pi is equal to 3.1415926. In your calculation functions,
display a message that indicates the value for radius read in and the result of the calculation. In
both cases, display the value to 7 digits of precision.

If the user enters a selection not present on your menu, indicate the error and try again until a
correct selection is made. Also, do not accept values for the radius that are less than 0.0.

My code so far :
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081`` ``````#include #include void circumference(double radius); void area(double radius); void volume(double radius); void print_menu(); const float PI=3.1415926; int main() { void(*f)(double)={circumference,area,volume}; size_t selection=0; while(selection!=3) { print_menu(); do { scanf("%d",&selection); }while(selection<0||selection>3); if(selection!=3) { (*f[selection])(selection); } else { printf("Done. Program terminated."); } } while(1); return 0; } void print_menu( void ) { printf( "=== Circles & Spheres Menu ===\n\n" "Please select from the options below:\n\n" "(0) Calculate the circumference of a circle.\n" "(1) Calculate the area of a circle.\n" "(2) Calculate the volume of a sphere.\n\n" "Enter your selection:"); } void circumference (double radius) { puts("Enter the radius of your figure:"); scanf("%f",&radius); printf("\nRadius= %f",radius); double circ = 2*PI*radius; printf("%s%.2f%s\n\n","\nThe circumference of the circle is ",circ," meters."); } void area (double radius) { printf("Enter the radius of your figure:"); scanf("%f",&radius); printf("\nRadius= %f",radius); double area = PI*radius*radius; printf("\n%s%.2f%s\n\n","The area of the circle is ",area," square meters."); } void volume (double radius) { puts("Enter the radius of your figure:"); scanf("%f",&radius); printf("\nRadius= %f",radius); double volume = (4/3)*PI*pow(radius,3); printf("%s%.2f%s\n\n","\nThe volume of the sphere is ",volume," cubed meters."); } ``````

Last edited on First: Don't use while(1), use something like getchar so you can analyze the output while you can exit properly when needed. Also, since the query message and code is the same for all functions, query it in main and pass the values correctly, otherwise the parameters are meaningless.

Also, you didn't specify a problem. I presume it's not behaving as expected, so what's the matter?
Topic archived. No new replies allowed.