繁体   English   中英

如果跑步者在健身追踪应用中保持同步,我如何跟踪?

[英]How can I keep track if runner is on pace in fitness tracking app?

我正在经历苹果公司的“使用Swift开发应用程序” iBook中遇到的挑战,并且在完成第2.2课-函数中完成健身应用程序遇到了障碍。 我想不出一个跟踪用户是否步调良好的公式。 我仍然是一个菜鸟,到目前为止,这是我的想法,显然无法准确跟踪进度。

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        if (currentDistance < 0.50 * totalDistance && currentTime > 0.40 * goalTime)     {
            print("You've got to push it just a bit harder!")
    }
    else {
            print("Keep it up!")
    }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)

书中的挑战告诉您要执行以下操作:您的健身跟踪应用程序将帮助跑步者保持步伐以实现自己的目标。 编写一个名为pacing的函数,该函数接受四个Double参数,分别称为currentDistance,totalDistance,currentTime和GoalTime。 您的函数应计算用户是否在达到或击败目标时间上。 如果是,请打印“保持!”,否则请打印“您必须将其推得更紧一点!”

我们知道Distance = Speed * Time,所以在这里您想知道当前速度是多少,并在此基础上打印相应的消息,因此可以尝试如下操作:

func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {

        let goalSpeed = totalDistance / goalTime
        let currentSpeed = currentDistance / currentTime

        if (currentSpeed < goalSpeed)     {
                print("You've got to push it just a bit harder!")
        }
        else {
                print("Keep it up!")
        }
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM