Programming in C I NEED HELP PLEASEE

thespeakerbox

Platinum Member
Nov 19, 2004
2,654
0
71
#include <stdio.h>
#define PI 3.14151
main() {
double radius,diameter,circumference,area,volume;
printf("Find nice uses of raii \n\n");
printf(" Radius Diameter Circumference\n");
printf(" --------- --------- -------------\n");
for (radius = 1; radius <= 20; radius += 1)
printf("%12.1lf%17.1lf\n", radius, radius*2);
for (diameter = 1; radius <= 20; radius += 1)
printf("%12.1lf%17.1lf\n", radius, radius*2);

system("pause");
return 0;
}


I create a table that can take a radii from 1 to 20 and tell me the diameter, circumference, area and volume.

I was able to find an example that let me move from radius to diameterm, but it doesnt work with that 12.1lf, 1731lf and i have no clue why not. Also, i cant figure out how to move past that stage and into finding circumference! can someone tell me what to do? I want to use the same radius to make diameter(done) , circumference(HELP), area(HELP) and volume(HELP)





(HELP)(HELP)(HELP)(HELP)(HELP)(HELP)(HELP)(HELP)
 

mundane

Diamond Member
Jun 7, 2002
5,603
8
81
Looks like what you're requesting is more of a math problem than C programming.

Diameter = 2 * radius
Circumference = Pi * diameter = Pi * 2 * radius
Area = Pi * radius^2
Volume (of a sphere) = 4/3 * Pi * radius^3
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
Looping with doubles? I haven't tried this in C but it looks like a recipe for mysterious off-by-one errors due to rounding.
 

fishbits

Senior member
Apr 18, 2005
286
0
0
In the for statement for diameter, you never set radius back to one (or changed the comparison to diameter).

Consider putting the statements following conditionals in curly braces, even if they're just a single line. I've gone back and added a line and not realized at the moment that it would alway execute. With the braces already in place, I minimize my chances of hosing myself.

In fact with braces, you can put all the work you need to do in the same 1-20 loop, but that might not be how this program is supposed to be written.

For as many significant digits as you are using, Pi is off.