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;

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.

Edited 5 Years Ago by Narue: n/a

This question has already been answered. Start a new discussion instead.