哪位大神帮忙看看哪里错了,跪谢大佬

输入一组学生成绩,统计优(90~100)、良(80~89)、中(70~79)、及格(60~69)及不及格(0~59)的人数及所占的百分比,以及总平均成绩。
#include <stdio.h>
void main()
{
int n9=0,n8=0,n7=0,n6=0,f=0,sum=0,c=0,x;
scanf("%d",&x);
while(0<=x<=100)
{
sum=sum+x,c++;
if(90<=x<=100)
n9++;
else if(80<=x<90)
n8++;
else if(70<=x<80)
n7++;
else if(60<=x<70)
n6++;
else f++;
}
printf_s("n9=%d,p9=%d,"n8=%d,p8=%d,"n7=%d,p7=%d,"n6=%d,p6=%d,"f=%d,pf=%d,average=%d",n9,n9*100/c+'%',n8,n8*100/c+'%',n7,n7*100/c+'%',n6,n6*100/c+'%',f,f*100/c+"%"",sum/c);
}

错误1:C中没有x<=y<=z这种写法,你要写做x<=y && y<=z

错误2:按你原本的意思是输入一个不在0至100之间的数就结束循环,否则继续,但是你的循环的最后并没有再次做scanf

错误3:C中没有x+"%"这种写法,你这样写程序会理解为你要把两个数字的ASCII进行相加。

错误4:printf_s用法错误

改动后的代码

#include <stdio.h>
void main()
{
int n9=0,n8=0,n7=0,n6=0,f=0,sum=0,c=0,x;
scanf("%d",&x);
while(0<=x && x<=100)
{
sum=sum+x,c++;
if(90<=x && x<=100)
n9++;
else if(80<=x && x<90)
n8++;
else if(70<=x && x<80)
n7++;
else if(60<=x && x<70)
n6++;
else f++;
scanf("%d",&x);
}
printf("n9=%d,p9=%d%\nn8=%d,p8=%d\nn7=%d,p7=%d%\nn6=%d,p6=%d%\nf=%d%,pf=%d%\naverage=%d",n9,n9*100/c,n8,n8*100/c,n7,n7*100/c,n6,n6*100/c,f,f*100/c,sum/c);
}

#include <stdio.h>
void main()
{
int n[]={0,0,0,0,0},sum=0,c=0,temp=0,x=0;
scanf("%d",&x);
while(0<=x && x<=100)
{
sum=sum+x,c++;
temp=x/10;
if(temp<=5) n[0]++;
else if(temp>=9) n[4]++;
else n[temp-5]++;
scanf("%d",&x);
}
printf("90~100 N=%d,R=%d%\n 80~89 N=%d,R=%d\n 70~79 N=%d,R=%d%\n 60~69 N=%d,R=%d%\n  0~59 N=%d%,R=%d%\nAverage=%d",n[4],n[4]*100/c,n[3],n[3]*100/c,n[2],n[2]*100/c,n[1],n[1]*100/c,n[0],n[0]*100/c,sum/c);
}


追问

那为什么无法输出呢

追答

无法输出具体是指啥,如果你要停顿,那在最后的}前加一行getchar();

追问

谢谢

温馨提示:答案为网友推荐,仅供参考
第1个回答  2018-04-10

参考代码:

#include <stdio.h>
void main()
{
    int n9=0,n8=0,n7=0,n6=0,f=0,sum=0,c=0,x;
    scanf("%d",&x);
    while(0<=x<=100)
    {
        sum=sum+x;
        c++;
        if(90<=x<=100)
            n9++;
        else if(80<=x<90)
            n8++;
        else if(70<=x<80)
            n7++;
        else if(60<=x<70)
            n6++;
        else f++;
    }
    printf("n9=%d,p9=%d%%,n8=%d,p8=%d%%,n7=%d,p7=%d%%,n6=%d,p6=%d%%,f=%d,pf=%d%%,average=%d",n9,n9*100/c,n8,n8*100/c,n7,n7*100/c,n6,n6*100/c,f,f*100/c,sum/c);
}

相似回答