@[zhy123456](/user/178294) 谢谢,这确实是一处错误,不过运行结果还是有问题
by zhs3202669494 @ 2020-01-25 17:11:11
```
#include <stdio.h>
#include <stdlib.h>
int judget(int*);
int main()
{
int budget[12];
int i;
int m;
for(i=0; i<12; i++)
{
scanf("%d",budget+i);
}
m=judget(budget);
printf("%d",m);
return 0;
}
int judget(int*a)
{
int temp=0;
int i;
int m=0;
for(i=0; i<12; i++)
{
if(300+temp-a[i]<0)
return -(i+1);
else if(300+temp-a[i]>=0&&300+temp-a[i]<100)//这里有改动
{
temp=300+temp-a[i];
}
else if(300+temp-a[i]>=100&&300+temp-a[i]<200)
{
m+=100;
temp=300+temp-a[i]-100;
}
else if(300+temp-a[i]>=200&&300+temp-a[i]<300)//这里有改动
{
m+=200;
temp=300+temp-a[i]-200;
}
else if(300+temp-a[i]>=300)
{
m+=300;
temp=300+temp-a[i]-300;
}
}
return m*1.2+temp;//这里有改动
}
```
by zhy137036 @ 2020-01-25 17:15:47
因为如果`300+temp-a[i]==0`,`temp`应该清零(钱都花光了)。但是原来的程序中遇到这种情况什么都不会发生,`temp`还是原来的值。
by zhy137036 @ 2020-01-25 17:18:20
@[zhs3202669494](/user/303464)
by zhy137036 @ 2020-01-25 17:18:27
@[zhy123456](/user/178294) 多谢多谢
by zhs3202669494 @ 2020-01-25 17:27:54