【发布时间】:2018-04-24 09:40:21
【问题描述】:
这是我正在使用的代码,
#include <stdio.h>
int main () {
/* variable definition: */
double sidea, sideb, sidec;
/* Prompt user for side a */
printf("Enter length of side a of the triangle: \n"); // Input the base
scanf("%f", &sidea);
/* Prompt user for side b */
printf("Enter the length of side b of the triangle: \n"); // Input the base
scanf("%f", &sideb);
/* Prompt user for side c */
printf("Enter the length of side c of the triangle \n");
scanf("%f", &sidec);
// Calculate the Perimeter
double perimeter= (sidea + sideb + sidec);
// Print the result
printf("The perimeter is : %f \n", perimeter);
return 0;
}
输入数据: 4.6 7.5 5.8
我一生都无法弄清楚为什么用于输入的任何值都会导致 0.000000。使用浮动似乎工作得很好。我错过了什么。谢谢!
【问题讨论】:
-
请查看How to Ask,然后编辑您的问题标题,使其看起来更像一个实际问题。
-
另外,显示引起您关注的输入数据。
-
谢谢你,我很抱歉。