mardi 29 janvier 2019

if statement always being skipped

I'm trying to make a basic little banking program to get my bearing with Go. I run the program and when I type in my answer for either of the if statements, the program just moves on. Any solutions?

here's my code;

package main
        import (
        "bufio"
        "fmt"
        "os"
        "strconv"
        "strings"
    )

    func main() {
        reader := bufio.NewReader(os.Stdin)
        fmt.Print("Enter your name: ")
        name, _ := reader.ReadString('\n')
        fmt.Print("Hello ", name)
        balance := 0
        fmt.Print("Do you want to deposite? (y/n) ")
        doDeposite, _ := reader.ReadString('\n')
        if strings.TrimRight(doDeposite, "\n") == "y" {
            fmt.Print("How much would you like to deposite? ")
            depositeAmount, _ := reader.ReadString('\n')
            da, _ := strconv.Atoi(depositeAmount)
            balance += balance + da
            fmt.Print("Your balance is ", balance)
        } else {
            fmt.Print("Would you like to withdraw?(y/n) ")
            doWithdraw, _ := reader.ReadString('\n')
            if strings.TrimRight(doWithdraw, "\n") == "y" {
                fmt.Print("How much would you like to withdraw? ")
                withdrawAmount, _ := reader.ReadString('\n')
                wa, _ := strconv.Atoi(withdrawAmount)
                balance += balance + wa
                fmt.Print("Your balance is ", balance)
            }

        }

    }

Aucun commentaire:

Enregistrer un commentaire