谁能帮我修改一下这段简单的C语言代码?我想要实现 继续吗?yes or no的功能!
答案:2 悬赏:70 手机版
解决时间 2021-03-29 08:20
- 提问者网友:未信
- 2021-03-29 02:30
谁能帮我修改一下这段简单的C语言代码?我想要实现 继续吗?yes or no的功能!
最佳答案
- 五星知识达人网友:傲气稳了全场
- 2021-03-29 03:22
#include "stdio.h"
void main()
{
int i,j,n;
char mon[12][100]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char *p[12];
for(i=0;i<12;i++)
p[i]=mon[i];
while(j) //do 去掉,你语法有点不熟练
{
printf("请输入月份号:\n");
scanf("%d",&n);
if(n<=0||n>12)
{printf("月份输入错误\n");}
printf("%s",*(p+n-1));
printf("\n");
getchar(); //这里加个,接收回车键
printf("还要继续吗?Y or N\n");
scanf("%c",&j);
if(j=='Y'||j=='y') j=1;
else
j=0; //这里
}
}追问最后一个注释“这里”似乎欲言又止啊,你想说啥?追答就是如果不是输入Y,y 那就设置 j=0;就是退出标记追问还有,我这边输入y之后就无法继续了(无法响应),故意输入13后也是……用你的编译器试试!追答把int j;改成 char j;就可以了,你输入13不满足,要强制性退出来,在
if(n<=0||n>12)
{printf("月份输入错误\n");
break; }//加个break;就可以
void main()
{
int i,j,n;
char mon[12][100]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char *p[12];
for(i=0;i<12;i++)
p[i]=mon[i];
while(j) //do 去掉,你语法有点不熟练
{
printf("请输入月份号:\n");
scanf("%d",&n);
if(n<=0||n>12)
{printf("月份输入错误\n");}
printf("%s",*(p+n-1));
printf("\n");
getchar(); //这里加个,接收回车键
printf("还要继续吗?Y or N\n");
scanf("%c",&j);
if(j=='Y'||j=='y') j=1;
else
j=0; //这里
}
}追问最后一个注释“这里”似乎欲言又止啊,你想说啥?追答就是如果不是输入Y,y 那就设置 j=0;就是退出标记追问还有,我这边输入y之后就无法继续了(无法响应),故意输入13后也是……用你的编译器试试!追答把int j;改成 char j;就可以了,你输入13不满足,要强制性退出来,在
if(n<=0||n>12)
{printf("月份输入错误\n");
break; }//加个break;就可以
全部回答
- 1楼网友:像个废品
- 2021-03-29 03:33
初学者,不过试过了能按你的意思运行。。。
#include
#include
#include
main()
{
int i,n,j;
char ch;
char mon[12][100]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char *p[12];
for(i=0;i<12;i++)
p[i]=mon[i];
do
{
j=0;
printf("请输入月份号:\n");
scanf("%d",&n);
if(n<=0||n>12)
{
printf("月份输入错误\n");
}
printf("%s",*(p+n-1));
printf("\n");
printf("还要继续吗?Y or N\n");
ch=getch();
putch(ch);
if(ch=='Y'||ch=='y')
j=1;
}
while(j);
}追问ch=getch();
putch(ch); ??
请问为何要加个putch(ch);只起到了输出字符的作用吧?追答额,putch可以显示在运行窗口的,如果没有这条语句,前面的会接收到输入了字符,但显示屏没有的,我用那个C语言编译运行过了。。。追问一定要ch=getch();?ch=getchar();好像不行啊,你那头试试!
#include
#include
#include
main()
{
int i,n,j;
char ch;
char mon[12][100]={"January","February","March","April","May","June","July","August","September","October","November","December"};
char *p[12];
for(i=0;i<12;i++)
p[i]=mon[i];
do
{
j=0;
printf("请输入月份号:\n");
scanf("%d",&n);
if(n<=0||n>12)
{
printf("月份输入错误\n");
}
printf("%s",*(p+n-1));
printf("\n");
printf("还要继续吗?Y or N\n");
ch=getch();
putch(ch);
if(ch=='Y'||ch=='y')
j=1;
}
while(j);
}追问ch=getch();
putch(ch); ??
请问为何要加个putch(ch);只起到了输出字符的作用吧?追答额,putch可以显示在运行窗口的,如果没有这条语句,前面的会接收到输入了字符,但显示屏没有的,我用那个C语言编译运行过了。。。追问一定要ch=getch();?ch=getchar();好像不行啊,你那头试试!
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯