Indentation for the logical if-else block is misplaced.Also no input was taken for height variable.
#include<stdio.h>
int main(){
float a, pi = 3.14, r, c, d, h;
printf("Program to calculate area of circle and volume of cylinder \n");
printf("select what you want to find?\n1.Area of circle\n2.Volume of cylinder\n");
scanf("%f", &c);
if (c == 1)
{
printf("Select unit\n1.CM\n2.Meter\n ");
scanf("%f", &d);
if (d == 1)
{
printf("enter radius in cm\n");
scanf("%f", &r);
a = (pi * r * r) / 100;
printf("the area of circle is \n%f cm", a);
}
if (d == 2)
{
printf("enter radius in meter\n");
scanf("%f", &r);
a = pi * r * r;
printf("the are of circle is \n%f meter", a);
}
}
else #This block is indented.
{
if (c == 2)
{
printf("select unit\n1.cm\n2.meter\n");
scanf("%f", &d);
}
if (d == 1)
{
printf("enter radius in cm\n");
scanf("%f", &r);
printf("enter height in cm\n");
scanf("%f", &h);
a = (pi * r * r * h) / 100;
printf("the volume of cylinder is\n%f cm", a);
}
if (d == 2)
{
printf("enter radius in meter \n");
scanf("%f", &r);
printf("enter the height of cylinder in meter \n");
scanf("%f", &h); #This is added
a = pi * r * r * h;
printf("the volume of cylinder is\n%f meter", a);
}
}
return 0;
}
solved How make this code shorter and accurate this code is just a basic code how to make it more efficient [closed]