Write a program to compute the area of a userdefined shape Y
Write a program to compute the area of a user-defined shape. Your program needs to have an enumeration date-type with four possible shapes (i) Circle (ii) Rectangle (iii) Parallelogram (iv) Triangle. Prompt the user to choose a shape to compute the area. Use the following formulas to calculate the area of the shape.
Triangle: 1/2* height* length of base
Rectangle: height* length
Parallelogram: height*length of base
Square: length*length
Please help me solve this in the simplest way/terms possible since I am new at learning how to code/program. Thank you!
Solution
#include <stdio.h>
enum Shape{Circle,Rectangle,Parallelogram,Triangle}; //enum for shapes
 int main(void)
 {
    int s;
    float radius,area,length,height;
   
    printf(\"\  Choose a shape to compute the area <0-Circle,1-Rectangle,2-parallelogram,3-triangle\");
    scanf(\"%d\",&s);
   
    if(s == Circle) //value of circle =0 by default in enum
    {
        printf(\"\ Enter the radius of the Circle\");
        scanf(\"%f\",&radius);
        area = 3.14*radius*radius; //compute area of Circle
        printf(\"\ Area of Circle : %.2f\",area);
    }
    else if(s == Rectangle) //value of retangle =1
    {
        printf(\"\ Enter the height of Rectangle\");
        scanf(\"%f\",&height);
        printf(\"\ Enter the length of Rectangle\");
        scanf(\"%f\",&length);
        area = height * length; //compute area of rectangle
        printf(\"\ Area of Rectangle : %.2f\",area);
    }
    else if(s == Parallelogram) //value of parallelogram =2
    {
        printf(\"\ Enter the height of Parallelogram\");
        scanf(\"%f\",&height);
        printf(\"\ Enter the length of base of Parallelogram\");
        scanf(\"%f\",&length);
        area = height * length; //compute area of parallelogram
        printf(\"\ Area of Parallelogram : %.2f\",area);
    }
    else if(s == Triangle) //value for rectangle is 3
    {
        printf(\"\ Enter the height of Triangle\");
        scanf(\"%f\",&height);
        printf(\"\ Enter the length of base of Triangle\");
        scanf(\"%f\",&length);
        area = 0.5 * height * length; //compute area of triangle
        printf(\"\ Area of Triangle : %.2f\",area);
    }
    return 0;
 }
output:


