我想做一个简单的程序来计算债务分期付款。要求是:
输入债务价值
输入分期付款多长时间
分期付款银行的上半年利率为11%,其余为8%
必须使用地图
这是我的代码
package main
import "fmt"
func main() {
fmt.Print("Input the debt value : ")
var debt int
fmt.Scanln(&debt)
fmt.Print("Input how long the installments : ")
var installment int
fmt.Scanln(&installment)
fmt.Println("====================================================")
fmt.Println("Total debt : ", debt)
fmt.Println("Installments : ", installment)
fmt.Println("====================================================")
var firstHalf = installment / 2
var pay int
for i := 1; i <= installment; i++ {
value := map[string]int{
"month": i,
"payment": pay,
}
if i <= firstHalf {
pay = (debt / installment) + (debt * 11 / 100)
fmt.Println(value["month"],"Installment with bank interest (11%) is", value["payment"])
} else {
pay = (debt / installment) + (debt * 8 / 100)
fmt.Println(value["month"],"Installment with bank interest (8%) is", value["payment"])
}
}
}
如果我运行代码,例如:
债务是10.000.000分期付款是7个月
这是输出:
1 Installment with bank interest (11%) is 0
2 Installment with bank interest (11%) is 2528571
3 Installment with bank interest (11%) is 2528571
4 Installment with bank interest (8%) is 2528571
5 Installment with bank interest (8%) is 2228571
6 Installment with bank interest (8%) is 2228571
7 Installment with bank interest (8%) is 2228571
我不知道为什么第一个索引总是0,甚至下一个计算都是对的。所以,我想要么是我使用了错误的语法,要么是我试图做一些无法做到的事情。也许最有可能有经验的人会立即看到问题所在。
慕村225694
GCT1015
相关分类