0

I wrote a program in which I found the area of cylinder using a functionarea with a return-type and without parameters. answerwas returned to main function. However, I am getting different output in main and a different output in area. The decimal places seem to be replaced by 0 in the main function. Why is it so? enter image description here

4

3 回答 3

2

将 area 的返回类型从 int 更改为 float

于 2013-03-27T03:39:30.757 回答
1

您的函数返回一个int截断值的任何实部的函数。

float area()
于 2013-03-27T03:38:23.967 回答
1

您的变量answer在区域函数中是浮点数,但区域函数的返回类型是int. 所以它在返回过程中输入大小写,在 main

int area(){
 ^  should be float

 float answer;

 // print float
 return answer;
}

int main(){
 answer = area(); // answer gets integral part
 // print int part
}
于 2013-03-27T03:39:25.750 回答