c++程序编写提问求解

一个小球从h的高度落下,每次反弹为前一高度的一半,问小球静止时所经过的路程(在反弹高度为1/10000米时视为静止),请问大神这重新怎么写

#include <iostream>
using namespace std;
int main()
{
    int M; //M表示初始高度,N表示弹起次数
    float s = 0;
    float h;
    cin >> M; //需要输入起始高度
    h = M; //h表示弹起高度
    while(h > 1.0/10000)
    {
        s += 2*h;//弹起和落下,但是第一次没有弹起,所以后面要减去多加的M
        h/=2;
    }
    s -= M; //减去第一次M
    cout  <<"总路程:" << s;
    return 0;
}

#include <iostream>
using namespace std;
int main()
{
    double h;
    cin>>h;
    double t = h/2;
    double s=0.0;
    while(t>0.00001)
    {
        s=s+2*t;
        t=t/2;   
    }
    s=s+h;
    cout<<s<<endl;
    return 0;

}

你题目的解答代码如下:

#include<iostream>
using namespace std;

int main()
{
    double h,s=0;
    cin >> h;
    while(h>1.0/10000)
    {
        s=s+h;
        h=h/2;
        s=s+h;
    }
    cout << s << endl;
    return 0;
}

如有帮助,望采纳!谢谢!