I am having trouble with getting my data to display. The program works fine if I choose option 7 to display the balances and it exits if the user enters option 8 but I can't get it to perform the other functions. Can anyone help me to figure out what is wrong with this. I hope that it is something simple that I can easily fix and not some fundamental flaw with what I am trying to do. Any help would be much appreciated.
Mike
Public Class Account
'declare instance variables for the two accounts
Private savingBalance As Double
Private checkingBalance As Double
Public Sub New(ByVal initBalance As Double)
savingBalance = 1000
checkingBalance = 1000
End Sub
Public Property Savings() As Double
Get
Return savingBalance
End Get
Set(ByVal value As Double)
savingBalance = value
End Set
End Property
Public Property Checking() As Double
Get
Return checkingBalance
End Get
Set(ByVal value As Double)
checkingBalance = value
End Set
End Property
Public Function deposit() As Double
Dim code As Integer
Dim amount As Double
If code = 1 Then
Console.WriteLine("How much money do you want to deposit?")
amount = Console.ReadLine()
savingBalance += amount
ElseIf code = 2 Then
Console.WriteLine("How much money do you want to deposit")
amount = Console.ReadLine()
checkingBalance += amount
End If
Return checkingBalance
Return savingBalance
End Function
Public Function withdraw() As Double
Dim code As Integer
Dim amount As Double
If code = 3 Then
If savingBalance > 0 Then
Console.WriteLine("How much money do you want to withdraw?")
amount = Console.ReadLine()
savingBalance -= amount
Else : WriteLine("You do not have enough money in savings account to withdraw.")
End If
ElseIf code = 4 Then
If checkingBalance > 0 Then
Console.WriteLine("How much money do you want to withdraw?")
amount = Console.ReadLine()
checkingBalance -= amount
Else : WriteLine("You do not have enough money in checking account to withdraw.")
End If
End If
Return checkingBalance
Return savingBalance
End Function
Function moveMoney() As Double
Dim code As Integer
Dim amount As Double
If code = 5 Then
If savingBalance >= amount Then
Console.WriteLine("How much money do you want to move?")
amount = Console.ReadLine()
checkingBalance += amount
savingBalance -= amount
Else : Console.WriteLine("You do not have enough money in savings to transfer this amount.")
End If
End If
If code = 6 Then
If checkingBalance >= amount Then
Console.WriteLine("How much money do you want to move?")
amount = Console.ReadLine()
savingBalance += amount
checkingBalance -= amount
Else : Console.WriteLine("You do not have enough money in checking to transfer this amount.")
End If
End If
Return checkingBalance
Return savingBalance
End Function
Public Sub displayBalance()
Console.WriteLine("Savings acount balance: {0:C}", savingBalance)
Console.WriteLine("Checking account balance:{0:C} ", checkingBalance)
End Sub
End Class
Option Strict On
Module accountTester
Sub Main()
Dim code As Integer
Dim account As New Account(code)
Console.WriteLine("Please select a transaction code: ")
Console.WriteLine("1 --- deposit to savings account")
Console.WriteLine("2 --- deposit to checking account")
Console.WriteLine("3 --- withdraw from savings account")
Console.WriteLine("4 --- withdraw from checking account")
Console.WriteLine("5 --- move money from savings account to checking account")
Console.WriteLine("6 --- move money from checking account to savings account")
Console.WriteLine("7 --- display balance")
Console.WriteLine("8 --- quit")
code = Convert.ToInt32(Console.ReadLine())
While code <> 8
Console.WriteLine("Please select a transaction code: ")
code = Convert.ToInt32(Console.ReadLine())
If code = 1 Then
account.deposit()
ElseIf code = 2 Then
account.deposit()
ElseIf code = 3 Then
account.withdraw()
ElseIf code = 4 Then
account.withdraw()
ElseIf code = 5 Then
account.moveMoney()
ElseIf code = 6 Then
account.moveMoney()
ElseIf code = 7 Then
account.displayBalance()
Else : Console.WriteLine("Thank you for your business.")
End If
End While
End Sub
End Module