问题在于m
by _O__o_ @ 2024-09-15 21:47:48
@[wangshengchen](/user/1400450) 应改成
```cpp
m=m*0.98;
```
by CSP400pts @ 2024-09-15 21:48:22
```
#include<bits/stdc++.h>
using namespace std;
int main()
{
double s,m=2.0,z=0.0;
int cnt=0;
cin>>s;
while(z<s)
{
z+=m;
m=m*0.98;
cnt++;
}
cout<<cnt;
return 0;
}
```
@[wangshengchen](/user/1400450)
by _O__o_ @ 2024-09-15 21:49:43
@[wangshengchen](/user/1400450) 啊,配!
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
double s,m=2;
double k=2;//统计长度
int cnt;
cin>>s;
while(k<s)
{
m*=0.98;
k+=m;
cnt++;
}
cout<<cnt+1;
return 0;
}
```
by CSP400pts @ 2024-09-15 21:50:36
你的m不能同时表示每步距离和共行距离,要在创建一个变量封装总共行驶的距离,其次,注意主函数内变量的初始化(cnt=0)
by _O__o_ @ 2024-09-15 21:50:54
@[_O__o_](/user/741120) @[CSP400pts](/user/1331383) 谢谢
by wangshengchen @ 2024-09-15 22:01:47
@[_O__o_](/user/741120) 能问一下m为啥不能同时表示每步距离和共行距离吗
by cccckick @ 2024-09-28 20:44:53
@[_O__o_](/user/741120) 知道了不用回复了谢谢
by cccckick @ 2024-09-28 20:46:00