hey all,
well I am trying to complete an assignment, and getting real close, but not close enough for my liking .
please take a look at the attached PDF, and then take a look at my program:
Code:
/* prog02assign.c */
#include <stdio.h>
/*#include <math.h>*/
int main(void)
{
int i;
float f;
unsigned double p = 3.140000000, d2;
printf("Please enter a decimal value between 1 and 100: ");
scanf("%d", &d2);
printf("\nVariable\t0 Decimals\t5 Decimals\t9 Decimals\n");
i = 2 * p;
printf("i (2*pi)\t%d\t\t%f\t%.9f\n", (int)i, (float)i, (float)i);
f = 3 * p;
printf("f (3*pi)\t%d\t\t%f\t%.9f\n", (int)f, f, f);
d2 = d2 * p;
printf("d2 (n*pi)\t%d\t\t%f\t%.9f\n\n\n", (int)d2, (float)d2, (float)d2);
return 0;
}
when you enter 35.628 see how close my results are to the screenshot? close, but not close enough IMO. math.h is commented out because my MSVC++ 6.0's math.h does not appear to define a symbolic constant for pi.
note that I am declaring an unsigned double, which I don't think is right, the compiler is issuing a warning for it. but without d2 being unsigned, I get ugly signed results printed for d2.
could anyone please help me with making my output more precise here? any help is greatly appreciated, I know this program is ugly, but its the closest I can get to the screenshot.
thank you in advance!