@[Wangyuqi123](/user/972388)
k应该定义为```double```类型而不是```int```类型
by cq_irritater @ 2023-04-20 21:33:35
没必要用for循环,用while就可以:
```cpp
#include<bits/stdc++.h>
using namespace std;
int main()
{
double n,s=2,sum=0;
cin>>n;
while(n>0){
n-=s;
s*=0.98;
sum+=1;
}
cout<<sum;
return 0;
}
```
保证n(距离)一定大于0.
by Syncc @ 2023-04-20 21:43:42
@[jinhouqi](/user/766788) 我没学while啊......新手
by Wen_Yun @ 2023-04-20 21:47:40
q=q/100*98 应放在s=s-q后面,因为还没等s=s-2的时候q已经取完98%了
by Syncc @ 2023-04-20 21:51:13
用$double$
by Shadow_T @ 2023-04-20 21:55:46
@[Wangyuqi123](/user/972388)
k一开始要等于0
by chenzher @ 2023-05-30 21:25:20
if没必要和循环条件重复了
可以再循环完之后在输出k
也可以
by youngcalm @ 2023-06-07 17:10:56
```cpp
#include <iostream>
using namespace std;
int main()
{
int s;
cin >> s;
int cnt = 0;
double start = 2;
for (; start < s; ++cnt)
{
s -= start;
start = start * 98 / 100;
}
cout << cnt + 1 << endl;
return 0;
}
```
用for也可以!
by youngcalm @ 2023-06-07 17:12:16