Reputation: 23
This is my code, written in Codeblocks with GNU compiler. But everytime, when I execute the program crashes:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <float.h>
int main()
{
const float pi=acos(-1.0);
double radius=0;
float kreisflaeche;
printf("Bitte den Radius eingeben.\n");
scanf ("%d", radius);
radius=radius*radius;
kreisflaeche=pi*radius;
printf("Mit dem eingegebenen Radius, erhält man %d als Kreisflaeche.", kreisflaeche);
return 0;
}
"the exe stopped working" but why?
Upvotes: 0
Views: 183
Reputation: 3456
This line scanf ("%d", radius);
should be scanf("%lf", &radius);
Radius is not an int
so you can't use %d
and you need to give the address of the variable where the input has to be stored hence using &
Here is an excerpt from the man page of scanf
The scanf() family of functions scans input according to format as described below. This format may contain conversion specifications; the results from such conversions, if any, are stored in the locations pointed to by the pointer arguments that follow format.
You can refer to this man page for more information on conversion and scanf()
in general
Upvotes: 6
Reputation: 2050
change
scanf ("%d", radius);
with
scanf ("%lf", &radius);
EDIT: added arc676's hint
Upvotes: 1