`a * 0.98`
改为
`a *= 0.98` 或 `a = a * 0.98`
by Handezheng @ 2024-07-20 15:32:07
将 `while` 里的 `>=` 改为 `<=` 即可。
`while(condition)` 中的 `condition` 是循环进行的条件,而不是循环结束的条件
by qazsedcrfvgyhnujijn @ 2024-07-20 15:34:25
`a * 0.98` 得改为 `a *= 0.98` (同 @Handezheng)
by qazsedcrfvgyhnujijn @ 2024-07-20 15:35:29
请养成在提交之前在本地跑样例和自测数据的好习惯
by qazsedcrfvgyhnujijn @ 2024-07-20 15:36:14
# AC了
```cpp
#include<bits/stdc++.h>
using namespace std;
int main(){
double m;
double n=0,s=2,x=0;
cin>>m;
while(x<m){
x+=s;
n++;
s*=0.98;
}
cout<<n<<endl;
return 0;
}
```
by jiangyichen_10 @ 2024-07-23 10:06:00
@[qaz12345678_](/user/1370412) 你犯了2个错误.
1.你的while()判断错了,应该为sum<=s;
2.a* 0应该为a*=0.98;
AC代码:
```cpp
#include <bits/stdc++.h>
using namespace std;
double s,sum = 0;
int cnt = 0;
double a = 2;
int main()
{
cin >> s;
while (sum <= s)
{
sum += a;
a *= 0.98;
cnt++;
}
cout<<fixed<<setprecision(1);
cout<<cnt;
}
```
by Bareks @ 2024-09-15 10:34:57