Calculating Coins

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MsBarnes
    New Member
    • Nov 2007
    • 1

    Calculating Coins

    I'm a newbie to the programming field and I really need help to understand what i'm doing wrong. This is the exercise i'm working on I need to create an application that allows the users to enter the number of pennies in a jar. The application then calculates the number of dollars, quarters, dimes, nickles, and pennies that he will receive when he cashes in the pennies. Any guidance would be greatly appreciated.

    MsBarnes

    This is the codes that I have started off with:
    Option Explicit On
    Option Strict On

    Public Class MainForm


    Private Sub xExitButton_Cli ck(ByVal sender As Object, ByVal e As System.EventArg s) Handles xExitButton.Cli ck
    Me.Close()
    End Sub

    Private Sub xCalculateButto n_Click(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles xCalculateButto n.Click
    ' calculate the total number of coins return


    ' declare variables
    Dim num As Integer
    Dim dollar As Integer
    Dim quarter As Integer
    Dim dime As Integer
    Dim nickle As Integer
    Dim penny As Integer

    ' calculate and display the amount of coins

    Integer.TryPars e(Me.xamountTex tBox.Text, num)
    Integer.TryPars e(Me.xDollarTex tBox.Text, dollar)
    dollar = num \ 100
    Integer.TryPars e(Me.xQuarterTe xtBox.Text, quarter)
    quarter = num Mod 100 \ 25
    Integer.TryPars e(Me.xDimeTextB ox.Text, dime)
    dime = num Mod 100 \ 10
    Integer.TryPars e(Me.xNickleTex tBox.Text, nickle)
    nickle = num Mod 100 \ 5
    Integer.TryPars e(Me.xPennyText Box.Text, penny)
    penny = num Mod 100 \ 1


    End Sub

    Private Sub xClearButton_Cl ick(ByVal sender As Object, ByVal e As System.EventArg s) Handles xClearButton.Cl ick
    ' prepare the screen for the next amount

    Me.xamountTextB ox.Text = String.Empty
    Me.xDollarTextB ox.Text = String.Empty
    Me.xQuarterText Box.Text = String.Empty
    Me.xDimeTextBox .Text = String.Empty
    Me.xNickleTextB ox.Text = String.Empty
    Me.xPennyTextBo x.Text = String.Empty


    End Sub
    End Class
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Have you made any progress on this?

    I suspect the order of precedence may have been the root of your problem. (Meaning, perhaps the division happened before the Mod.)

    Comment

    Working...