I have a homework in VB.NET where I have to calculate the number of dollars, quarters, dimes, nickels, an pennies I will receive when I cash in my pennies at a bank. The number of pennies I have can be random numbers. And so far, my code is here:
Option Explicit On
Option Strict Off
Option Infer Off
Public Class frmMain
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalc_Click(sender As Object, e As EventArgs) Handles btnCalc.Click
Dim intDollars As Integer
Dim intQuarters As Integer
Dim intDimes As Integer
Dim intNickels As Integer
Dim intPennies As Integer
Integer.TryParse(txtNumPennies.Text, intDollars)
intDollars = txtNumPennies.Text 100
txtDollars.Text = Convert.ToString(intDollars)
Integer.TryParse(txtNumPennies.Text, intQuarters)
intQuarters = (txtNumPennies.Text - txtDollars.Text * 100) 25
txtQuarters.Text = Convert.ToString(intQuarters)
Integer.TryParse(txtNumPennies.Text, intDimes)
intDimes = (txtNumPennies.Text Mod 25) 10
txtDimes.Text = Convert.ToString(intDimes)
Integer.TryParse(txtNumPennies.Text, intNickels)
intNickels = (txtNumPennies.Text Mod 10) 5
txtNickels.Text = Convert.ToString(intNickels)
Integer.TryParse(txtNumPennies.Text, intPennies)
intPennies = (txtNumPennies.Text Mod 5) 1
txtPennies.Text = Convert.ToString(intPennies)
End Sub
Private Sub txtNumPennies_TextChanged(sender As Object, e As EventArgs) Handles txtNumPennies.TextChanged
txtDollars.Text = String.Empty
txtQuarters.Text = String.Empty
txtDimes.Text = String.Empty
txtNickels.Text = String.Empty
txtPennies.Text = String.Empty
End Sub
End Class
Somehow, it is not calculating right, especially the nickles. I would gladly appreciate any helpful tips! Thank you so much in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…