求c语言大神指点switch语句的用法
想编一个根据出生年月日计算已经活了多少天的程序可是不知道switch语句哪里错了我是初学拜请赐教#include<stdio.h>intmain(){inty,m,d,n...
想编一个根据出生年月日计算已经活了多少天的程序
可是不知道switch语句哪里错了
我是初学
拜请赐教
#include<stdio.h>
int main()
{
int y,m,d,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12;
printf("hellow sweety please tell me which year did you born:\n");
scanf("%d",&y);
printf("and next the month :\n");
scanf("%d",&m);
printf("at last the day of your date:\n");
scanf("%d",&d);
switch (m);
case '1':
n1=(31-d+334)+(y-1)*365;
printf("your life has gone %d days!\n",n1);
break;
case '3':
n3=(31-d+275)+(y-1)*365;
printf("your life has gone %d days!\n",n3);
break;
case'5':
n5=(31-d+214)+(y-1)*365;
printf("your life has gone %d days!\n",n5);
break;
这只是一部分 展开
可是不知道switch语句哪里错了
我是初学
拜请赐教
#include<stdio.h>
int main()
{
int y,m,d,n1,n2,n3,n4,n5,n6,n7,n8,n9,n10,n11,n12;
printf("hellow sweety please tell me which year did you born:\n");
scanf("%d",&y);
printf("and next the month :\n");
scanf("%d",&m);
printf("at last the day of your date:\n");
scanf("%d",&d);
switch (m);
case '1':
n1=(31-d+334)+(y-1)*365;
printf("your life has gone %d days!\n",n1);
break;
case '3':
n3=(31-d+275)+(y-1)*365;
printf("your life has gone %d days!\n",n3);
break;
case'5':
n5=(31-d+214)+(y-1)*365;
printf("your life has gone %d days!\n",n5);
break;
这只是一部分 展开
2个回答
展开全部
switch (m){//大括号
case 1://不要单引号 int类型
n1=(31-d+334)+(y-1)*365;
printf("your life has gone %d days!\n",n1);
break;
case 3:
n3=(31-d+275)+(y-1)*365;
printf("your life has gone %d days!\n",n3);
break;
case 5:
n5=(31-d+214)+(y-1)*365;
printf("your life has gone %d days!\n",n5);
break;
defoult://可以加上这个
break;
}
case 1://不要单引号 int类型
n1=(31-d+334)+(y-1)*365;
printf("your life has gone %d days!\n",n1);
break;
case 3:
n3=(31-d+275)+(y-1)*365;
printf("your life has gone %d days!\n",n3);
break;
case 5:
n5=(31-d+214)+(y-1)*365;
printf("your life has gone %d days!\n",n5);
break;
defoult://可以加上这个
break;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询