DEV Community

bappasaha
bappasaha

Posted on

Make Bikash app using Go

πŸš€ Learn Any Programming Language Faster β€” by Building Simple, Practical Projects! πŸ§ πŸ’»

Today, I built a simple USSD-based Bikash (mobile banking) console app in Go (Golang).

πŸ” This basic app includes:

βœ… Variables and data types

πŸ”„ Loops and conditional logic

πŸ“₯ User input handling

πŸ“€ Console output

πŸ“¦ Function modularity

πŸš€ Step-by-Step: How I Developed My Simple Bikash App in Go
βœ… Started with basic functionality: Display welcome message and show a simple menu.

🧠 Used if-else statements: Handled user choices like checking balance, cash in, and cash out.

βœ”οΈ Added validation: Ensured users can’t cash in or out with invalid amounts (e.g., negative or zero).

πŸ” Introduced a loop: Used a for loop to keep the app running without restarting it.

πŸ›‘ Added exit condition: Allowed users to exit the app gracefully using a menu option.

πŸ”„ Replaced if-else with switch: Made the code cleaner and easier to manage.

πŸ”² Run:

  • cd BikashApp
  • go run bikash.go

I want to make a simple bikash app which we see in our real life
by typing *247#.


πŸ”² Final full code

// Run: go run bikash.go

package main

import "fmt"

func main() {

    accountBalance := 1000.00



    // Ask user to dial *247# before starting
    var ussdInput string
    fmt.Print("Please dial *247# to start your transaction: ")
    fmt.Scan(&ussdInput)

    if ussdInput != "*247#" {
        fmt.Println("Invalid USSD code. Exiting...")
        return
    }

    fmt.Println("Welcome to Fake-Bikash App")
    fmt.Println("-------------------------")

    for {
        fmt.Println("What do you want to do?")
        fmt.Println("1. Check Your Balance")
        fmt.Println("2. Cash In")
        fmt.Println("3. Cash Out")
        fmt.Println("4. Exit Fake-Bikash App")

        var choice int
        fmt.Print("Enter your option: ")
        fmt.Scan(&choice)
        // fmt.Println("You have selected option:", choice)

        switch choice {
        case 1:
            fmt.Printf("You Balance is : %.2f Tk\n", accountBalance)
        case 2:
            //user cash in
            fmt.Print("Enter your Cash in amount: ")
            var cashInAmount float64
            fmt.Scan(&cashInAmount)
            fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

            if cashInAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                // return;
                continue
            }

            accountBalance = accountBalance + cashInAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        case 3:
            //user cash out
            fmt.Print(("Enter your Cash out amount: "))
            var cashOutAmount float64
            fmt.Scan((&cashOutAmount))

            if cashOutAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                continue
            }

            if cashOutAmount > accountBalance {
                fmt.Println("Insufficient balance!")
                // return
                continue
            }

            accountBalance = accountBalance - cashOutAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        default:
            fmt.Println("-----Thanks for chosing Fake-Bikash App----")
            return

        }

    }

}
Enter fullscreen mode Exit fullscreen mode

output:


❯ go run bikash.go
Please dial *247# to start your transaction: 77878
Invalid USSD code. Exiting...
❯ clear
❯ go run bikash.go
Please dial *247# to start your transaction: *247#
Welcome to Fake-Bikash App
-------------------------
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 1
You Balance is : 1000.00 Tk
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 2
Enter your Cash in amount: 200
You entered: 200.00 Tk
Balanced Updated!Current balance is: 1200.00 Tk
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 1
You Balance is : 1200.00 Tk
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 3
Enter your Cash out amount: -90
Invalid amount! Please enter a amount greater than 0.
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 3
Enter your Cash out amount: 1100
Balanced Updated!Current balance is: 100.00 Tk
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 1
You Balance is : 100.00 Tk
What do you want to do?
1. Check Your Balance
2. Cash In
3. Cash Out
4. Exit Fake-Bikash App
Enter your option: 4
-----Thanks for chosing Fake-Bikash App----
Enter fullscreen mode Exit fullscreen mode

  1. Basic task
package main

import "fmt"

func main(){
    fmt.Println("Welcome to Bikash App");
    fmt.Println("What do you want to do?");
    fmt.Println("1. Check Your Balance");
    fmt.Println("2. Cash In");
    fmt.Println("3. Cash Out");
    fmt.Println("4. Exit Bikash App");
}
Enter fullscreen mode Exit fullscreen mode
  1. Next I implemnt if-else based on user choice.
//Run: go run bikash.go

package main

import "fmt"

func main() {

    accountBalance :=1000.00;

    fmt.Println("Welcome to Fake-Bikash App")
    fmt.Println("-------------------------")
    fmt.Println("What do you want to do?")
    fmt.Println("1. Check Your Balance")
    fmt.Println("2. Cash In")
    fmt.Println("3. Cash Out")
    fmt.Println("4. Exit Fake-Bikash App")

    var choice int
    fmt.Print("Enter your option: ")
    fmt.Scan(&choice)
    // fmt.Println("You have selected option:", choice)

    if choice == 1 {
        fmt.Printf("You Balance is : %.2f Tk\n", accountBalance);
    }else if choice == 2 {

        //user cash in
        fmt.Print("Enter your Cash in amount: ");
        var cashInAmount float64;
        fmt.Scan(&cashInAmount,)
        fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

        accountBalance=accountBalance+cashInAmount;
        fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance);
    }else if choice==3 {
        fmt.Print(("Enter your Cash out amount: "))
        var cashOutAmount float64;
        fmt.Scan((&cashOutAmount));

        accountBalance=accountBalance-cashOutAmount;
        fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance);
    }else{
        fmt.Println("Exiting Fake-Bikash App")

    }
}
Enter fullscreen mode Exit fullscreen mode
  1. Add Vaditation for cash in and cash out part
// Run: go run bikash.go
package main

import "fmt"

func main() {

    accountBalance := 1000.00

    fmt.Println("Welcome to Fake-Bikash App")
    fmt.Println("-------------------------")

    fmt.Println("What do you want to do?")
    fmt.Println("1. Check Your Balance")
    fmt.Println("2. Cash In")
    fmt.Println("3. Cash Out")
    fmt.Println("4. Exit Fake-Bikash App")

    var choice int
    fmt.Print("Enter your option: ")
    fmt.Scan(&choice)
    // fmt.Println("You have selected option:", choice)

    if choice == 1 {
        fmt.Printf("You Balance is : %.2f Tk\n", accountBalance)
    } else if choice == 2 {

        //user cash in
        fmt.Print("Enter your Cash in amount: ")
        var cashInAmount float64
        fmt.Scan(&cashInAmount)
        fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

        if cashInAmount <= 0 {
            fmt.Println("Invalid amount! Please enter a amount greater than 0.")
            return
        }

        accountBalance = accountBalance + cashInAmount
        fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
    } else if choice == 3 {
        fmt.Print(("Enter your Cash out amount: "))
        var cashOutAmount float64
        fmt.Scan((&cashOutAmount));


        if cashOutAmount <=0{
            fmt.Println("Invalid amount! Please enter a amount greater than 0.")
        };

        if cashOutAmount > accountBalance {
            fmt.Println("Insufficient balance!")
            return
        }

        accountBalance = accountBalance - cashOutAmount
        fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
    } else {
        fmt.Println("Exiting Fake-Bikash App")

    }
}

Enter fullscreen mode Exit fullscreen mode
  1. Add for loop so that i can selete option as much as i need
// Run: go run bikash.go
package main

import "fmt"

func main() {

    accountBalance := 1000.00

    for i := 0; i < 5; i++ {
        fmt.Println("Welcome to Fake-Bikash App")
        fmt.Println("-------------------------")

        fmt.Println("What do you want to do?")
        fmt.Println("1. Check Your Balance")
        fmt.Println("2. Cash In")
        fmt.Println("3. Cash Out")
        fmt.Println("4. Exit Fake-Bikash App")

        var choice int
        fmt.Print("Enter your option: ")
        fmt.Scan(&choice)
        // fmt.Println("You have selected option:", choice)

        if choice == 1 {
            fmt.Printf("You Balance is : %.2f Tk\n", accountBalance)
        } else if choice == 2 {

            //user cash in
            fmt.Print("Enter your Cash in amount: ")
            var cashInAmount float64
            fmt.Scan(&cashInAmount)
            fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

            if cashInAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                return
            }

            accountBalance = accountBalance + cashInAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        } else if choice == 3 {
            fmt.Print(("Enter your Cash out amount: "))
            var cashOutAmount float64
            fmt.Scan((&cashOutAmount))

            if cashOutAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
            }

            if cashOutAmount > accountBalance {
                fmt.Println("Insufficient balance!")
                return
            }

            accountBalance = accountBalance - cashOutAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        } else {
            fmt.Println("Exiting Fake-Bikash App")

        }
    }

}

Enter fullscreen mode Exit fullscreen mode
  1. Add infinite time to run the loop and add condition for loop break

// Run: go run bikash.go
package main

import "fmt"

func main() {

    accountBalance := 1000.00;

    fmt.Println("Welcome to Fake-Bikash App")
    fmt.Println("-------------------------")

    for  {
        fmt.Println("What do you want to do?")
        fmt.Println("1. Check Your Balance")
        fmt.Println("2. Cash In")
        fmt.Println("3. Cash Out")
        fmt.Println("4. Exit Fake-Bikash App")

        var choice int
        fmt.Print("Enter your option: ")
        fmt.Scan(&choice)
        // fmt.Println("You have selected option:", choice)

        if choice == 1 {
            fmt.Printf("You Balance is : %.2f Tk\n", accountBalance)
        } else if choice == 2 {

            //user cash in
            fmt.Print("Enter your Cash in amount: ")
            var cashInAmount float64
            fmt.Scan(&cashInAmount)
            fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

            if cashInAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                // return;
                continue
            }

            accountBalance = accountBalance + cashInAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        } else if choice == 3 {
            fmt.Print(("Enter your Cash out amount: "))
            var cashOutAmount float64
            fmt.Scan((&cashOutAmount))

            if cashOutAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
            }

            if cashOutAmount > accountBalance {
                fmt.Println("Insufficient balance!")
                return
            }

            accountBalance = accountBalance - cashOutAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        } else {
            fmt.Println("-----Thanks for chosing Fake-Bikash App----")
            break;

        }
    }

}

Enter fullscreen mode Exit fullscreen mode
  1. Add switch case
// Run: go run bikash.go
package main

import "fmt"

func main() {

    accountBalance := 1000.00

    fmt.Println("Welcome to Fake-Bikash App")
    fmt.Println("-------------------------")

    for {
        fmt.Println("What do you want to do?")
        fmt.Println("1. Check Your Balance")
        fmt.Println("2. Cash In")
        fmt.Println("3. Cash Out")
        fmt.Println("4. Exit Fake-Bikash App")

        var choice int
        fmt.Print("Enter your option: ")
        fmt.Scan(&choice)
        // fmt.Println("You have selected option:", choice)

        switch choice {
        case 1:
            fmt.Printf("You Balance is : %.2f Tk\n", accountBalance)
        case 2:
            //user cash in
            fmt.Print("Enter your Cash in amount: ")
            var cashInAmount float64
            fmt.Scan(&cashInAmount)
            fmt.Printf("You entered: %.2f Tk\n", cashInAmount)

            if cashInAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                // return;
                continue
            }

            accountBalance = accountBalance + cashInAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        case 3:
            //user cash out
            fmt.Print(("Enter your Cash out amount: "))
            var cashOutAmount float64
            fmt.Scan((&cashOutAmount))

            if cashOutAmount <= 0 {
                fmt.Println("Invalid amount! Please enter a amount greater than 0.")
                continue
            }

            if cashOutAmount > accountBalance {
                fmt.Println("Insufficient balance!")
                // return
                continue
            }

            accountBalance = accountBalance - cashOutAmount
            fmt.Printf("Balanced Updated!Current balance is: %.2f Tk\n", accountBalance)
        default:
            fmt.Println("-----Thanks for chosing Fake-Bikash App----")
            return

        }

    }

}

## Optimized Final version Code

Enter fullscreen mode Exit fullscreen mode


go
package main

import "fmt"

var accountBalance float64 =1000.00
func main(){

// var ussdInput string
// fmt.Print("Please dial *247# to start your transaction: ")
// fmt.Scan(&ussdInput)

// if ussdInput != "*247#" {
//  fmt.Println("Invalid USSD code. Exiting...")
//  return
// }

fmt.Println("Welcome to Fake-Bikash App")
fmt.Println("-------------------------")

for {
    showMenu()
    var choice int
    fmt.Scan(&choice)

    switch choice {
    case 1:
        checkBalance()
    case 2:
        cashIn()
    case 3:
        cashOut()
    case 4:
        fmt.Println("-----Thanks for choosing Fake-Bikash App----")
        return
    default:
        fmt.Println("Invalid choice. Please try again.")
    }
}
Enter fullscreen mode Exit fullscreen mode

}

func showMenu(){
fmt.Println("What do you want to do?")
fmt.Println("1. Check Your Balance")
fmt.Println("2. Cash In")
fmt.Println("3. Cash Out")
fmt.Println("4. Exit Fake-Bikash App")
}

func checkBalance(){
fmt.Printf("Your Balance is: %.2f Tk\n", accountBalance)
}

func cashIn() {
var amount float64
fmt.Print("Enter your Cash In amount: ")
fmt.Scan(&amount)

if !isValidAmount(amount) {
    return
}

accountBalance += amount
fmt.Printf("Balance Updated! Current balance is: %.2f Tk\n", accountBalance)
Enter fullscreen mode Exit fullscreen mode

}

func cashOut() {
var amount float64
fmt.Print("Enter your Cash Out amount: ")
fmt.Scan(&amount)

if !isValidAmount(amount) {
    return
}

if amount > accountBalance {
    fmt.Println("Insufficient balance!")
    return
}

accountBalance -= amount
fmt.Printf("Balance Updated! Current balance is: %.2f Tk\n", accountBalance)
Enter fullscreen mode Exit fullscreen mode

}

func isValidAmount(amount float64) bool {
if amount <= 0 {
fmt.Println("Invalid amount! Please enter an amount greater than 0.")
return false
}
return true
}





Enter fullscreen mode Exit fullscreen mode

Top comments (0)