主题:[讨论]亟待解决的问题!
小弟是初学者 深知论坛卧虎藏龙 有些代码不知道哪个地方出错了希望给看一下 每次总是输出的时候出错 不管输入什么都是出来的0.000很是疑惑不解 希望一下 感激不尽!
顺便一提我用的是win7 用的编译器是win-tc!本代码纯属是为了 巩固所学的内容
代码如下:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
int choice;
int year;
double a,b,c,area,s,max;
char oper;
printf("* * * * * * * * Menu * * * * * * * *\n");
printf("* 1.The biggest number *\n");
printf("* 2.Reconize the leap year *\n");
printf("* 3.The area of the triangle *\n");
printf("* 4.Simple calculation *\n");
printf("* 0.Exit *\n");
printf("* * * * * * * * * * * * * * * * * * *\n");
printf("Please select(0-4):");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Please input number(a,b,c):");
scanf("%f%f%f",&a,&b,&c);
if (a>b)
{if (a>c)
max=a;
else
max=c;
}
else
{if (b>c)
max=b;
else
max=c;
}
printf("The max nimber is %f\n",max);
break;
case 2:
printf("Please input the year:");
scanf("%d",&year);
if ((year%4==0)&&(year%100!=0)||(year%400==0))
printf("%4d is a leap year",year);
else
printf("%4d is not a leap year",year);
break;
case 3:
printf("Please input a,b,c:");
scanf("%f%f%f",&a,&b,&c);
if (a<=0||b<=0||c<=0||a+b<c||b+c<a||a+c<b)
printf("data error!\n");
else
{
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area=%f",area);
}
break;
case 4:
printf("input expression[a op b]:");
scanf("%f%c%f",&a,&oper,&b);
switch(oper)
{
case '+':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a+b);
break;
case '-':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a-b);
break;
case '*':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a*b);
break;
case '/':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a/b);
break;
default:printf("input error!\n");
}
break;
case 0 :
exit(0);
break;
default:printf("error!\n");
}
getch();
}
谢谢
有什么错误还请一定要指出来!
顺便一提我用的是win7 用的编译器是win-tc!本代码纯属是为了 巩固所学的内容
代码如下:
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
int choice;
int year;
double a,b,c,area,s,max;
char oper;
printf("* * * * * * * * Menu * * * * * * * *\n");
printf("* 1.The biggest number *\n");
printf("* 2.Reconize the leap year *\n");
printf("* 3.The area of the triangle *\n");
printf("* 4.Simple calculation *\n");
printf("* 0.Exit *\n");
printf("* * * * * * * * * * * * * * * * * * *\n");
printf("Please select(0-4):");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Please input number(a,b,c):");
scanf("%f%f%f",&a,&b,&c);
if (a>b)
{if (a>c)
max=a;
else
max=c;
}
else
{if (b>c)
max=b;
else
max=c;
}
printf("The max nimber is %f\n",max);
break;
case 2:
printf("Please input the year:");
scanf("%d",&year);
if ((year%4==0)&&(year%100!=0)||(year%400==0))
printf("%4d is a leap year",year);
else
printf("%4d is not a leap year",year);
break;
case 3:
printf("Please input a,b,c:");
scanf("%f%f%f",&a,&b,&c);
if (a<=0||b<=0||c<=0||a+b<c||b+c<a||a+c<b)
printf("data error!\n");
else
{
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("area=%f",area);
}
break;
case 4:
printf("input expression[a op b]:");
scanf("%f%c%f",&a,&oper,&b);
switch(oper)
{
case '+':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a+b);
break;
case '-':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a-b);
break;
case '*':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a*b);
break;
case '/':
printf("%5.1f%c%5.1f=%5.1f\n",a,oper,b,a/b);
break;
default:printf("input error!\n");
}
break;
case 0 :
exit(0);
break;
default:printf("error!\n");
}
getch();
}
谢谢
有什么错误还请一定要指出来!