3 回答
TA贡献1803条经验 获得超3个赞
为了扩展迭戈的答案,您已经知道了
var ratex float64 = 1 + interest
在定义利息之前,所以它是0,ratex变成1。
var logi float64 = math.Log(ratex)
并且由于ratex为1,且log 1为0,logi变为0。然后通过除以logi定义周期,即0,因此将得到+ inf。
您应该做的是在获得感兴趣的输入后,将值分配给ratex。
TA贡献1895条经验 获得超7个赞
当您分配ratex的值时,兴趣为0。因此,增加您的值所需的时间将是无穷大。您想要的是:
func numPeriod() {
fmt.Println("Enter interest amount: ")
fmt.Scanf("%g", &interest)
var ratex float64 = 1 + interest / 100 //used for (1 + i)
fmt.Println("Enter present value: ")
fmt.Scanf("%g", &presentValue)
fmt.Println("Enter future value: ")
fmt.Scanf("%g", &futureValue)
var logfvpvFactor float64 = futureValue / presentValue
var logi float64 = math.Log(ratex)
var logfvpv float64 = math.Log(logfvpvFactor)
period = logfvpv / logi
fmt.Printf("Number of period/s is = %g\n", period)
}
TA贡献1942条经验 获得超3个赞
(09:54) jnml@fsc-r550:~/src/tmp/SO/13739751$ cat main.go
package main
import (
"fmt"
"math"
)
func main() {
var i, pv, fv float64
fmt.Println("Enter interest amount: ")
fmt.Scanf("%g", &i)
fmt.Println("Enter present value: ")
fmt.Scanf("%g", &pv)
fmt.Println("Enter future value: ")
fmt.Scanf("%g", &fv)
fmt.Printf("Number of period/s is = %g\n", math.Log(fv/pv)/math.Log(1+i))
}
(09:54) jnml@fsc-r550:~/src/tmp/SO/13739751$ go run main.go
Enter interest amount:
.1
Enter present value:
100
Enter future value:
200
Number of period/s is = 7.272540897341713
(09:54) jnml@fsc-r550:~/src/tmp/SO/13739751$
- 3 回答
- 0 关注
- 1031 浏览
添加回答
举报