I am having an issue with the following program. This is just a simple program that calculates the surface area/volume of a cylinder. For some reason this executes JUST fine in CodeBlocks. Everything works exactly as it should and I get the correct values.
However, when I try to run it in the IDE that my professor forces us to use I always get 0 for values. If I change all the variables to int and use %d it will compile fine in both, but I lose accuracy. Double is required. Is %lf the correct scanf() function to use for doubles? I have tried many different things and I cannot get it to work properly in the IDE for my class.
Here is the following code:
Code:#include <stdio.h> #define PI 3.141593 double computation(double l, double r) { if (2*r >= l) { printf("These dimensions do not define a valid tank"); } else { double volCYL = (PI * r * r * l); double volSPH = (4.0/3.0 * PI * r * r * r); double surfCYL = (2 * PI * r * l); double surfSPH = (4 * PI * r * r); printf("\n"); printf("A cylindrical tank of length %.3lf and radius %.3lf with inverted spherical\n", l,r); printf("caps has\n"); printf("volume: %.3lf\n", volCYL-volSPH); printf("and\n"); printf("surface area: %.3lf\n", surfCYL+surfSPH); printf("\n"); printf("Program Termination.\n"); } return 0; } double length = 0; double radius = 0; int main() { printf("ACME Truck Company\n"); printf("\n"); printf("This program will calculate the volume and surface area of the x-11\n"); printf("cylindrical tank\n"); printf("Enter the length of the tank (feet)"); scanf("%lf",&length); while (length < 10 || length > 20) { printf("Invalid value\n"); printf("Please enter a value between 10 and 20:"); scanf("%lf", &length); getchar(); } printf("Enter the radius of the tank (feet)"); scanf("%lf", &radius); while (radius < 3 || radius > 6) { printf("Invalid value\n"); printf("Please enter a value between 3 and 6:"); scanf("%lf", &radius); getchar(); } computation(length,radius); return 0; }
Any help would be much appreciated!



LinkBack URL
About LinkBacks



