This would be my last reply i gtg somewhere.Originally Posted by rhymewithnothin
peace
This would be my last reply i gtg somewhere.Originally Posted by rhymewithnothin
peace
That still won't make 1/2 evaluate to 0.5. See my above post.Originally Posted by jcarouth
Thank you very much. When I compile and link now all the error messages are gone. Thanks again. I'll check back if I need more help.
OK all the erros are gone, but when I try to run the I/O, it will ask me what shape I want to find the area of, and when I type what I want, it just ends the program. Here is the completed code if someone wants to put it in their compiler and try to figure it out...
Thanks again.Code:/*This program will compute the area of a rectangle, */ /*triangle, circle, ellipse, and sphere. */ #include <stdio.h> #include <math.h> #define PI 3.141593 int main(void) { /* Declare first variable. */ char shape, rectangle, triangle, circle, ellipse, sphere; /* Determine which shape to find the area of */ printf("Find the area of a rectangle, triangle, circle, ellipse, or sphere?"); scanf("%c",&shape); if (shape == rectangle){ /* Declare set of variables for this shape */ float lengthRect, widthRect, areaRect; printf("Enter the length. \n"); scanf("%lf",&lengthRect); printf("Enter the width. \n"); scanf("%lf",&widthRect); /* Compute the area */ areaRect = (lengthRect*widthRect); printf("The area of the rectangle is " "%5.2lf \n",areaRect); } else if (shape == triangle){ /* Declare set of variables for this shape */ float baseTri, heightTri, areaTri; printf("Enter the base. \n"); scanf("%lf",&baseTri); printf("Enter the height. \n"); scanf("%lf",&heightTri); /* Compute the area */ areaTri = (.5)*(baseTri*heightTri); printf("The area of the triangle is " "%5.2lf \n",areaTri); } else if (shape == circle){ /* Declare set of variables for this shape */ float radiusCirc, areaCirc; printf("Enter the radius. \n"); scanf("%lf",&radiusCirc); /* Compute the area */ areaCirc = PI*(radiusCirc*radiusCirc); printf("The area of the circle is " "%5.2lf \n",areaCirc); } else if (shape == ellipse){ /* Declare set of variables for this shape */ float semiaxisA, semiaxisB, areaEllipse; printf("Enter the length of semiaxisA. \n"); scanf("%lf",&semiaxisA); printf("Enter the length of semiaxisB. \n"); scanf("%lf",&semiaxisB); /* Compute the area */ areaEllipse = (PI*semiaxisA*semiaxisB); printf("The area of the ellipse is " "%5.2lf \n",areaEllipse); } else if (shape == sphere){ /* Declare set of variables for this shape */ float radiusSphere, areaSphere; printf("Enter the length of the radius. \n"); scanf("%lf",&radiusSphere); /* Compute the area */ areaSphere = (4*PI*radiusSphere*radiusSphere); printf("The surface area of the sphere is " "%5.2lf \n",areaSphere); } return 0; }
Originally Posted by cwr
meant to be ((double)(1)/2)....sorry
I changed all the comparisons to characters since you are comparing against a character.Code:/*This program will compute the area of a rectangle, */ /*triangle, circle, ellipse, and sphere. */ #include <stdio.h> #include <math.h> #define PI 3.141593 int main(void) { /* Declare first variable. */ char shape; //char shape, rectangle, triangle, circle, ellipse, sphere; /* Determine which shape to find the area of */ printf("Find the area of a rectangle, triangle, circle, ellipse, or sphere?"); scanf("%c",&shape); if (shape == 'r'){ /* Declare set of variables for this shape */ float lengthRect, widthRect, areaRect; printf("Enter the length. \n"); scanf("%lf",&lengthRect); printf("Enter the width. \n"); scanf("%lf",&widthRect); /* Compute the area */ areaRect = (lengthRect*widthRect); printf("The area of the rectangle is " "%5.2lf \n",areaRect); } else if (shape == 't'){ /* Declare set of variables for this shape */ float baseTri, heightTri, areaTri; printf("Enter the base. \n"); scanf("%lf",&baseTri); printf("Enter the height. \n"); scanf("%lf",&heightTri); /* Compute the area */ areaTri = (.5)*(baseTri*heightTri); printf("The area of the triangle is " "%5.2lf \n",areaTri); } else if (shape == 'c'){ /* Declare set of variables for this shape */ float radiusCirc, areaCirc; printf("Enter the radius. \n"); scanf("%lf",&radiusCirc); /* Compute the area */ areaCirc = PI*(radiusCirc*radiusCirc); printf("The area of the circle is " "%5.2lf \n",areaCirc); } else if (shape == 'e'){ /* Declare set of variables for this shape */ float semiaxisA, semiaxisB, areaEllipse; printf("Enter the length of semiaxisA. \n"); scanf("%lf",&semiaxisA); printf("Enter the length of semiaxisB. \n"); scanf("%lf",&semiaxisB); /* Compute the area */ areaEllipse = (PI*semiaxisA*semiaxisB); printf("The area of the ellipse is " "%5.2lf \n",areaEllipse); } else if (shape == 's'){ /* Declare set of variables for this shape */ float radiusSphere, areaSphere; printf("Enter the length of the radius. \n"); scanf("%lf",&radiusSphere); /* Compute the area */ areaSphere = (4*PI*radiusSphere*radiusSphere); printf("The surface area of the sphere is " "%5.2lf \n",areaSphere); } return 0; }
The user needs to enter an r for rectangle, t for triangle, et cetera. There are ways to implement using the entire word, ie rectangle. It runs right now. I only tested that it will accept r for rectangle, and it appears that you need to check your computational algorithm as it gave me an area of 0.00 for a 2 by 3 rectangle.
Can do. I'll see what I can do. Thanks.