function problem

Why the result is wrong?when i enter 4 and 5 for square. the square answer is 0.0.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  #include <stdio.h>
#include <math.h>
double calcSquareArea (double width, double height)
{
	double area;
	area = width * height;
	return area;
}
double calcCircleArea (double radius)
{
	double area;
	area =22.0/7 *radius *radius;
	return area;
}
int main ()
{
	double radius,l,t,sarea,carea;
	printf("Enter width and height:\n");
	scanf(" %f %f",&l, &t);
	sarea =calcSquareArea (l,t);
	printf("Square Area: %.1f\n",sarea);
	printf("Enter radius:\n");
	scanf("%f",&radius);
	carea= calcCircleArea(radius);
	printf("Circle Area: %.1f\n",carea);
	return 0;
}
Last edited on
In function ‘int main()’:
|19 col 23| warning: format ‘%f’ expects argument of type ‘float*’, but argument 2 has type ‘double*’ [-Wformat=]
|19 col 23| warning: format ‘%f’ expects argument of type ‘float*’, but argument 3 has type ‘double*’ [-Wformat=]
|23 col 20| warning: format ‘%f’ expects argument of type ‘float*’, but argument 2 has type ‘double*’ [-Wformat=]

I thought %f is for double and float . Am i right?
No you are not right. %f is for float, %lf is for double.
http://www.mobidev.com/shalan/scanf_printf.htm
L or i?
Thnx . you are right. lf not f.
Topic archived. No new replies allowed.