Calculating area of a triangle
这程序着实让我汗颜一把,在是否Countinue的时候,总是不能输入Y or N,经过KingsanChen的帮助,用fflush(stdin)解决了,我得加快学习的步伐了。
在C94环境下,需用double定义类型;在C99环境下,需用float定义变量类型才可以正确运行。
在C94环境下,需用double定义类型;在C99环境下,需用float定义变量类型才可以正确运行。
//Calculating area of a triangle
#include <stdio.h>
#include <math.h>
#include <ctype.h>
int main(void)
{
double a,b,c,t,s;
char ch;
do
{
printf("Enter 3 sides of traingle:");
scanf("%lf%lf%lf",&a,&b,&c);
if(((a+b)>c)||((a+c)>b)||((c+b)>a))
{
t=(a+b+c)/2;
s=sqrt(t*(t-a)*(t-b)*(t-c));
printf("S=%.2lf\n",s);
}
else
printf("Can't build a triangle with these 3 sides.\n");
fflush(stdin);
printf("\rContinue another caculation?(Y/N)");
ch=toupper(getchar());
}
while(ch=='Y');
//system("pause");
return 0;
}
评论