其他分享
首页 > 其他分享> > Go-家庭收支软件(面向过程)

Go-家庭收支软件(面向过程)

作者:互联网

image

package main

import (
	"fmt"
)

func main() {
	key := ""
	loop := true
	balance := 10000.0
	count := false
	money := 0.0
	note := ""
	details := "收支\t账户金额\t收支金额\t说明"
	for {
		fmt.Println("\n-----------家庭收支记账软件-------------")
		fmt.Println("             1.收支明细")
		fmt.Println("             2.登记收入")
		fmt.Println("             3.登记支出")
		fmt.Println("             4.退出软件")
		fmt.Println("请选择(1-4)")
		fmt.Scanln(&key)
		switch key {
		case "1":
			if !count {
				fmt.Println("当前没有收支明细")
			} else {
				fmt.Println("-------当前收支明细记录---------")
				fmt.Println(details)
			}
		case "2":
			fmt.Println("本次收入金额:")
			fmt.Scanln(&money)
			balance += money
			fmt.Println("本次收入说明:")
			fmt.Scanln(&note)
			details += fmt.Sprintf("\n收入\t%v\t\t%v\t\t%v", balance, money, note)
			count = true
		case "3":
			fmt.Println("本次支出金额:")
			fmt.Scanln(&money)
			if money > balance {
				fmt.Println("余额不足")
				break
			}
			balance -= money
			fmt.Println("本次支出说明:")
			fmt.Scanln(&note)
			details += fmt.Sprintf("\n支出\t%v\t\t%v\t\t%v", balance, money, note)
			count = true
		case "4":
			fmt.Println("你确定要退出吗?y/n")
			flag := ""
			for {

				fmt.Scanln(&flag)
				if flag == "y" {
					loop = false
					break
				} else if flag == "n" {
					break
				} else {
					fmt.Println("你的输入有误,请重新输入 y/n")
				}
			}
		default:
			fmt.Println("请输入正确的选项..")
		}
		if !loop {
			break
		}
	}
	fmt.Println("已退出软件")
}

image

image

标签:balance,Scanln,money,fmt,收支,Println,面向,Go,t%
来源: https://www.cnblogs.com/jgg54335/p/15838829.html