某大学的GPA(绩点)计算规则如下:
课程百分制成绩90分对应绩点4.0,超过90分的,按90分计;如不足90分,则课程绩点 = 4.0 * 分数/90。
学生综合绩点按该生已修的各门课程绩点结合学分加权平均而得。
现有步步同学入学后的已修课程(共5门)成绩表如下,请编程计算其GPA。
#include
int main(void)
{
int a,b,c,d,e;
int f,h,j,k,l;
double a1,c1,e1,h1,k1;
scanf("%d(后面还有四个,但CSDN上不让输入重复的d),下同",&a,&b,&c,&d,&e);
scanf("%d ",&f,&h,&j,&k,&l);
if(a>=90)
{a1=4.0;}
else
{a1=a4.0/90;}
if(e>=90)
{e1=4.0;}
else
{e1=e4.0/90;}
if(c>=90)
{c1=4.0;}
else
{c1=c4.0/90;}
if(h>=90)
{h1=4.0;}
else
{h1=h4.0/90;}
if(k>=90)
{k1=4.0;}
else
{k1=k4.0/90;}
printf("GPA:%.2f",(a1b+c1d+e1f+h1j+k1l)/17);
return 0;
}
a.c: In function ‘main’:
a.c:7:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
a.c:8:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
答案是正确的,但是在PTA上出现了上述报错;从网上也搜寻过相关答案,但是没有好的解决办法。
想知道出现这种情况是什么问题,以及相关的解决办法。
scanf改为scanf_s
vs通病 将scanf修改为scanf_s或者在vs设置中禁用4996警告即可