hi everyone! i'm trying to do some homework and this program i wrote that's supposed to read in numbers and do some calculations isn't working right. The problem right now is that no matter what number i put in for radius it gives me the invalid number result, please help me and thanks in advance.
Code:
#include <stdio.h>
#define PI 3.141593
int main (void)
{
double len, rad, SA, vol;
printf("Enter the length of the tank\(feet\)\n");
scanf("%lf", &len);
while(len<10 || len>20)
{
printf("Invalid length, please try again.\n");
scanf("%lf", &len);
}
printf("Enter the radius of the tank\(feet\)\n");
scanf("%lf", &rad);
while(rad<3 || rad>6)
{
printf("Invalid radius, please try again.\n");
scanf("%lf", &rad);
}
while(2*rad>=len)
{
printf("Non-real tank,Invalid input, please try again.\n");
printf("Enter the length of the tank\(feet\)\n");
scanf("%lf", &len);
while(len<10 || len>20)
{
printf("Invalid input, please try again.\n");
scanf("%lf", &len);
}
printf("Enter the radius of the tank\(feet\)\n");
scanf("%lf", &rad);
while(rad<3 || len>6)
{
printf("Invalid input, please try again.\n");
scanf("%lf", &rad);
}
}
vol = (PI*rad*rad*len)-(4/3*PI*rad*rad*rad);
SA = (2*PI*rad*len)+(4*PI*rad*rad);
printf("A cylindrical tank of length %.3lf and radius %.3lf with inverted spherical \ncaps has\nvolume: %.3lf\nand\nsurface area: %lf",len, rad, vol,
SA);
return 0;
}