hi, i'm trying to make a simple program to calculate the area and perimeter of a circle, but there's a little problem, whenever i enter a floating point number as the radius, like say 2.5 it calculates as if i entered only 2(without the .5) ( i hope that makes sense lol my english is bad) now I'm guessing it's because scanf("%d") can't read floating point numbers..but after i changed it to %f it still wouldn't work as intended :( - anyway here is the code any help is greatly appreciated :)

int Circle_Radius;
	double Circle_Area, Circle_Perimeter, pi;


	printf ("Enter Circle Radius: ");
	scanf_s ("%d", &Circle_Radius);

	pi =  3.14;
	Circle_Area =  pi * Circle_Radius * Circle_Radius;
	Circle_Perimeter = 2 * pi * Circle_Radius;

	printf ("Circle Perimeter is %.2f\n", Circle_Perimeter);
	printf ("Circle Area is %.2f\n", Circle_Area);

return 0;

this is a c++ forum.

this is not a c forum.

now I'm guessing it's because scanf("%d") can't read floating point numbers

Good call. %f doesn't work either because scanf() is expecting a pointer to float and you pass a pointer to a double. Use %lf for reading doubles with scanf().

this is a c++ forum.

this is not a c forum.

C++ supports scanf() and printf() too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.