c语言解决餐饮评分问题,有能给点思路不,学生党

img

问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果

开一个Count数组,然后不断读入就好了,望采纳

#include<stdio.h>
#include<math.h>

int Count[10];

void slove(){
    int n = 0;
    int k;
    while(scanf("%d",&k) && k != -1) {
        if(k < 1 || k > 5) {
            printf("This is a error input!");
            continue;
        }
        n++;
        Count[k] ++;
    }
    printf("n = %d\n",n);
    printf("Grade(*)\tCount(n)\tPercent(%)\n");
    for(int i = 5;i > 0; --i) {
        double Pr = (Count[i]*100.0)/(n);
        printf("%d\t\t%d\t\t%lf\n",i,Count[i],Pr);
    }
}

int main()
{
    
    slove();
    
    return 0;
}
/*
5
5
5
5
5
5
5
5
4
4
4
4
4
4
3
-1

*/