VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 307,099 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,026 people online right now. Registration is fast and FREE... Join Now!




Visual Basic Pennies Calculator

 

Visual Basic Pennies Calculator

kardana

24 Sep, 2009 - 05:12 AM
Post #1

New D.I.C Head
*

Joined: 22 Sep, 2009
Posts: 10

I am a beginner (only 3 weeks) in Visual Basic and am having trouble with the pennies calculator. I need to create an application which should calculate the number of dollars, quarters, dimes, nickels and pennies a person will receive when they cash in the pennies at a bank.

Eveything seems to be working fine except the nickles.... Does anyone have any hints for me?

CODE
  Option Explicit On
Option Strict Off
Option Infer Off

Public Class frmMain


    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPennies.Click

    End Sub
    Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblQuarters.Click

    End Sub
    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDimes.Click

    End Sub
    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblNickels.Click

    End Sub
    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDollars.Click

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'closes application'
        Me.Close()

    End Sub

    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        'calculates number of dollars, quarters, dimes, nickels and pennies

        'declare variables
        Dim intDollars As Integer
        Dim intQuarters As Integer
        Dim intDimes As Integer
        Dim intNickels As Integer
        Dim intPennies As Integer

        ' Calculate and display the total number of dollars, quarters, dimes, nickels and pennies
        Integer.TryParse(txtNumberPennies.Text, intDollars)
        intDollars = txtNumberPennies.Text \ 100
        lblDollarsCalc.Text = Convert.ToString(intDollars)

        Integer.TryParse(txtNumberPennies.Text, intQuarters)
        intQuarters = (txtNumberPennies.Text - lblDollarsCalc.Text * 100) \ 25
        lblQuartersCalc.Text = Convert.ToString(intQuarters)

        Integer.TryParse(txtNumberPennies.Text, intDimes)
        intDimes = (txtNumberPennies.Text Mod 25) \ 10
        lblDimesCalc.Text = Convert.ToString(intDimes)

        Integer.TryParse(txtNumberPennies.Text, intNickels)
        intNickels = (txtNumberPennies.Text Mod 10) \ 5
        lblNickelsCalc.Text = Convert.ToString(intNickels)

        Integer.TryParse(txtNumberPennies.Text, intPennies)
        intPennies = (txtNumberPennies.Text Mod 5) \ 1
        lblPenniesCalc.Text = Convert.ToString(intPennies)

    End Sub


This post has been edited by kardana: 24 Sep, 2009 - 07:44 AM

User is offlineProfile CardPM
+Quote Post


kardana

RE: Visual Basic Pennies Calculator

24 Sep, 2009 - 07:45 AM
Post #2

New D.I.C Head
*

Joined: 22 Sep, 2009
Posts: 10

I figured it out but it seems like there would be an easier way than the code I used below:
CODE


'declare variables
        Dim intDollars As Integer
        Dim intQuarters As Integer
        Dim intDimes As Integer
        Dim intNickels As Integer
        Dim intPennies As Integer

        ' Calculate and display the total number of dollars, quarters, dimes, nickels and pennies
        Integer.TryParse(txtNumberPennies.Text, intDollars)
        intDollars = txtNumberPennies.Text \ 100
        lblDollarsCalc.Text = Convert.ToString(intDollars)

        Integer.TryParse(txtNumberPennies.Text, intQuarters)
        intQuarters = (txtNumberPennies.Text - lblDollarsCalc.Text * 100) \ 25
        lblQuartersCalc.Text = Convert.ToString(intQuarters)

        Integer.TryParse(txtNumberPennies.Text, intDimes)
        intDimes = (txtNumberPennies.Text Mod 25) \ 10
        lblDimesCalc.Text = Convert.ToString(intDimes)

        Integer.TryParse(txtNumberPennies.Text, intNickels)
        intNickels = (txtNumberPennies.Text - (lblDollarsCalc.Text * 100) - (lblQuartersCalc.Text * 25) - (lblDimesCalc.Text * 10)) \ 5
        lblNickelsCalc.Text = Convert.ToString(intNickels)

        Integer.TryParse(txtNumberPennies.Text, intPennies)
        intPennies = (txtNumberPennies.Text - (lblDollarsCalc.Text * 100) - (lblQuartersCalc.Text * 25) - (lblDimesCalc.Text * 10) - (lblNickelsCalc.Text * 5)) \ 1
        lblPenniesCalc.Text = Convert.ToString(intPennies)

    End Sub



QUOTE(kardana @ 24 Sep, 2009 - 05:12 AM) *

I am a beginner (only 3 weeks) in Visual Basic and am having trouble with the pennies calculator. I need to create an application which should calculate the number of dollars, quarters, dimes, nickels and pennies a person will receive when they cash in the pennies at a bank.

Eveything seems to be working fine except the nickles.... Does anyone have any hints for me?

CODE
  Option Explicit On
Option Strict Off
Option Infer Off

Public Class frmMain


    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblPennies.Click

    End Sub
    Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblQuarters.Click

    End Sub
    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDimes.Click

    End Sub
    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblNickels.Click

    End Sub
    Private Sub Label10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblDollars.Click

    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        'closes application'
        Me.Close()

    End Sub

    Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
        'calculates number of dollars, quarters, dimes, nickels and pennies

        'declare variables
        Dim intDollars As Integer
        Dim intQuarters As Integer
        Dim intDimes As Integer
        Dim intNickels As Integer
        Dim intPennies As Integer

        ' Calculate and display the total number of dollars, quarters, dimes, nickels and pennies
        Integer.TryParse(txtNumberPennies.Text, intDollars)
        intDollars = txtNumberPennies.Text \ 100
        lblDollarsCalc.Text = Convert.ToString(intDollars)

        Integer.TryParse(txtNumberPennies.Text, intQuarters)
        intQuarters = (txtNumberPennies.Text - lblDollarsCalc.Text * 100) \ 25
        lblQuartersCalc.Text = Convert.ToString(intQuarters)

        Integer.TryParse(txtNumberPennies.Text, intDimes)
        intDimes = (txtNumberPennies.Text Mod 25) \ 10
        lblDimesCalc.Text = Convert.ToString(intDimes)

        Integer.TryParse(txtNumberPennies.Text, intNickels)
        intNickels = (txtNumberPennies.Text Mod 10) \ 5
        lblNickelsCalc.Text = Convert.ToString(intNickels)

        Integer.TryParse(txtNumberPennies.Text, intPennies)
        intPennies = (txtNumberPennies.Text Mod 5) \ 1
        lblPenniesCalc.Text = Convert.ToString(intPennies)

    End Sub



User is offlineProfile CardPM
+Quote Post

mark.bottomley

RE: Visual Basic Pennies Calculator

24 Sep, 2009 - 08:12 AM
Post #3

D.I.C Addict
****

Joined: 22 Apr, 2009
Posts: 868



Thanked: 148 times
My Contributions
The problem you had was as follows: take 26 cents - should be 1 quarter and a penny, but the mod 10 \ 5 gives you a nickel. It fails because a quarter is not a multiple of a dime. You can do it more simply - see the following post: http://www.dreamincode.net/forums/index.ph...&hl=balance
User is offlineProfile CardPM
+Quote Post

kardana

RE: Visual Basic Pennies Calculator

24 Sep, 2009 - 08:47 AM
Post #4

New D.I.C Head
*

Joined: 22 Sep, 2009
Posts: 10

QUOTE(mark.bottomley @ 24 Sep, 2009 - 08:12 AM) *

The problem you had was as follows: take 26 cents - should be 1 quarter and a penny, but the mod 10 \ 5 gives you a nickel. It fails because a quarter is not a multiple of a dime. You can do it more simply - see the following post: http://www.dreamincode.net/forums/index.ph...&hl=balance


thanks Mark. I've looked at the other code but it hasn't sunk in yet..I'll keep looking at it. I'm sure once my brain gets accustomed to this it will become easier smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 12:09PM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month