计算长方体的体积和表面积。测试了以下,貌似scanf不能正常赋值给变量。计算结果为-0.00 ,- 0.00. 在vc++ 下编译能正确计算出结果,但是又不能执行do - while循环。在手机C4driod上运行,一切正常。请问这是为什么。codebloacks 用的GCC编译器。
#include <stdio.h>
int main()
{
char answer = 'Y';
double length = 0.0;
double width = 0.0;
double height = 0.0;
double volume = 0.0;
double area = 0.0;
do
{
printf("Enter the value of length,width,height(separate them with space): \n");
scanf("%lf,%lf,%lf",&length,&width,&height);
volume = length*width*height;
area = (length*width+length*height+height*width)*2;
printf("The volume is %15.2lf\n",volume);
printf("The area is %15.2lf",area);
printf("\nCalculate another cuboid?(Y/N)\n");
scanf("%c",&answer);
getchar();
}while(toupper(answer) == 'Y');
return 0;
}
#include <stdio.h>
int main()
{
char answer = 'Y';
double length = 0.0;
double width = 0.0;
double height = 0.0;
double volume = 0.0;
double area = 0.0;
do
{
printf("Enter the value of length,width,height(separate them with space): \n");
scanf("%lf,%lf,%lf",&length,&width,&height);
volume = length*width*height;
area = (length*width+length*height+height*width)*2;
printf("The volume is %15.2lf\n",volume);
printf("The area is %15.2lf",area);
printf("\nCalculate another cuboid?(Y/N)\n");
scanf("%c",&answer);
getchar();
}while(toupper(answer) == 'Y');
return 0;
}