一个很简单的C语言问题,求高手解答,谢谢!
#include<stdio.h>voidmain(){intscore;printf("请输入分数\n");scanf("分数=%d\n",&score);while(...
#include <stdio.h>
void main()
{
int score;
printf("请输入分数\n");
scanf("分数= %d\n",&score);
while(score>100||score<0)
{
printf("错误,请重新输入\n");
scanf("分数= %d\n",&score);
}
switch(score)
{
case 100:printf("%s","A");break;
case 90 :printf("%s","B");break;
case 80 :printf("%s","C");break;
case 70 :printf("%s","D");break;
case 60 :printf("%s","D");break;
case 50 :printf("%s","D");break;
case 40 :printf("%s","D");break;
case 30 :printf("%s","D");break;
case 20 :printf("%s","D");break;
case 10 :printf("%s","D");break;
case 0 :printf("%s","D");break;
}
}
程序是按分数输出A,B,C;但是输入成绩后还是一直在while循环里面,不知道错误出在哪里,谢谢! 展开
void main()
{
int score;
printf("请输入分数\n");
scanf("分数= %d\n",&score);
while(score>100||score<0)
{
printf("错误,请重新输入\n");
scanf("分数= %d\n",&score);
}
switch(score)
{
case 100:printf("%s","A");break;
case 90 :printf("%s","B");break;
case 80 :printf("%s","C");break;
case 70 :printf("%s","D");break;
case 60 :printf("%s","D");break;
case 50 :printf("%s","D");break;
case 40 :printf("%s","D");break;
case 30 :printf("%s","D");break;
case 20 :printf("%s","D");break;
case 10 :printf("%s","D");break;
case 0 :printf("%s","D");break;
}
}
程序是按分数输出A,B,C;但是输入成绩后还是一直在while循环里面,不知道错误出在哪里,谢谢! 展开
3个回答
展开全部
scanf("分数= %d\n",&score);是错的,这样会导致你无法输入任何数据。
不信你可以先给score赋一个初值,然后
printf("%d",score);就会发现score永远是初值。
应该写成scanf("%d",&score);
如果你需要显示“分数=”,应该再用一个printf
#include<stdio.h>
void main()
{
int score;
printf("请输入分数:\n");
scanf("%d",&score);
printf("分数= %d\n",score);
while((score<0)||(score>100))
{
printf("错误,请重新输入\n");
scanf("分数= %d\n",&score);
}
switch(score)
{
case 100:printf("%s","A");break;
case 90 :printf("%s","B");break;
case 80 :printf("%s","C");break;
case 70 :printf("%s","D");break;
case 60 :printf("%s","D");break;
case 50 :printf("%s","D");break;
case 40 :printf("%s","D");break;
case 30 :printf("%s","D");break;
case 20 :printf("%s","D");break;
case 10 :printf("%s","D");break;
case 0 :printf("%s","D");break;
}
}
展开全部
scanf("分数= %d\n",&score);//不是printf没有输出功能,仅限格式化类型,且对于整形
数据\n是不允许在里面的,两种改法:
scanf("分数= %d",&score);//输入 分数=12
或者scanf("%d",&score);//直接输入数字 12
还有switch里面也错了
数据\n是不允许在里面的,两种改法:
scanf("分数= %d",&score);//输入 分数=12
或者scanf("%d",&score);//直接输入数字 12
还有switch里面也错了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
多了scanf("分数= %d\n",&score);去掉试试
更多追问追答
追问
不对,没用啊
追答
printf("错误,请重新输入\n");在这后面加break;跳出循环试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询