qq_40701177
qq_40701177
采纳率100%
2017-10-19 05:23

大家帮忙看一看 很急的

已采纳

这个作业做的程序 为什么输入数据之后 加权平均分是一大堆数字串 好多位的数 还是个负的
#include
void main()
{
int A,B,C,D,E,F,G,H,I,J,K,L;
float a,b,c,d,e,f,g,h,i,j,k,l;

printf ("Please input your calculas scores:");
scanf ("%d",&A);
printf ("Please input your credit scores:");
scanf ("%f",&a);

printf ("Please input your circuit scores:");
scanf ("%d",&B);
printf ("Please input your credit scores:");
scanf ("%f",&b);

printf ("Please input your linea scores:");
scanf ("%d",&C);
printf ("Please input your credit scores:");
scanf ("%f",&c);

printf ("Please input your military theory scores:");
scanf ("%d",&D);
printf ("Please input your credit scores:");
scanf ("%f",&d);

printf ("Please input your physics scores:");
scanf ("%d",&E);
printf ("Please input your credit scores:");
scanf ("%f",&e);

printf ("Please input your English scores:");
scanf ("%d",&G);
printf ("Please input your credit scores:");
scanf ("%f",&g);

printf ("Please input your physical scores:");
scanf ("%d",&H);
printf ("Please input your credit scores:");
scanf ("%f",&h);

printf ("Please input your chemistry scores:");
scanf ("%d",&I);
printf ("Please input your credit scores:");
scanf ("%f",&i);

printf ("Please input your philosophy scores:");
scanf ("%d",&J);
printf ("Please input your credit scores:");
scanf ("%f",&j);

printf ("Please input your computer science scores:");
scanf ("%d",&K);
printf ("Please input your credit scores:");
scanf ("%f",&k);

printf ("Please input your history scores:");
scanf ("%d",&L);
printf ("Please input your credit scores:");
scanf ("%f",&l);

float sum1,sum2;

float w1,w2,w3,w4,w5,w6,w7,w8,w9,w10,w11,w12;

sum1=a+b+c+d+e+f+g+h+i+j+k+l;
w1=a/sum1;
w2=b/sum1;
w3=c/sum1;
w4=d/sum1;
w5=e/sum1;
w6=f/sum1;
w7=g/sum1;
w8=h/sum1;
w9=i/sum1;
w10=j/sum1;
w11=k/sum1;
w12=l/sum1;
sum2=A*w1+B*w2+C*w3+D*w4+E*w5+F*w6+G*w7+H*w8+I*w9+J*w10+K*w11+L*w12;

printf("credit:%6.2f,weighting total:%6.2f\n",sum1,sum2);

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

7条回答

  • qq_40701177 qq_40701177 4年前

    真是让各位见笑了 我找到错误了图片说明

    少打了f的一段 麻烦各位了

    点赞 评论 复制链接分享
  • Loe_Pold 我是涵涵呀 4年前

    代码可以写的更好,试试数组和循环,估计你是大一才学C

    点赞 2 评论 复制链接分享
  • qq_38349698 东流长江水 4年前

    因为你有逻辑错误,导致打印出错,打印出了计算机内存里的随机值。随机值就是一个长整型的数,或正或负。

    点赞 评论 复制链接分享
  • jianyuxian2016 jianyuxian2016 4年前

    你试下看全部数据输入1最后输出结果是什么。还有你的程序没有分行。

    点赞 评论 复制链接分享
  • llf919329450 Next5Soft 4年前

    楼主你好,这时候应该考虑下是不是因为加权平均后,精度超过了float类型的范围,试试用double定义,并把printf("%6.2f");中的%6.2f改成%lf。。

    点赞 评论 复制链接分享
  • Loe_Pold 我是涵涵呀 4年前

    你写的代码没有问题的,初值不用给,刚刚看到条件反射了,后来仔细再打开帖子一看,老脸一红

    点赞 评论 复制链接分享
  • Loe_Pold 我是涵涵呀 4年前

    给SUM1和SUM2初值

    点赞 评论 复制链接分享

为你推荐