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

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

Join 300,436 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,471 people online right now. Registration is fast and FREE... Join Now!




Change code

 

Change code

colemand

3 Jul, 2009 - 04:41 PM
Post #1

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 2

Good Afternoon,

My name is Dianne Coleman and I am working on some homework. I have written the code but it is not running. What I would like someone to do for me is to tell me what I haven't done. I don't want you to write the code for me just let me know what I am missing so that I can fix it. This is how I learn. I am using VB 2008 Express.
CODE

'Project name: Pennies Project
' Project purpose:  The project calculates the total number of pennies into dollars, quarters, dimes, nickels and pennies
'                   when taken to the bank.
' Created/revised:  Dianne P. Coleman on 14 June 2009

Public Class MainForm

    Private Sub xExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xExitButton.Click
        Me.Close()
    End Sub

    Private Sub xCalcButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles xCalcButton.Click

        'Calculate the pennies into dollars, quarters, dimes, nickles

        'declare variables  
        Dim amountOwed, amountPaid, changeDue As Decimal
        Dim dollarChange As Integer
        Dim quarterChange As Integer
        Dim dimeChange As Integer
        Dim nickelChange As Integer
        Dim pennyChange As Integer
        Dim intTotal As Integer
        'assign value to variables
        amountOwed = Decimal.Parse(Me.xChangeLabel.Text)
        amountPaid = Decimal.Parse(Me.xPaidTextBox.Text)

        'perform calculations
        changeDue = amountPaid - amountOwed
        dollarChange = intTotal \ 100
        intTotal = intTotal Mod 100
        quarterChange = intTotal \ 25
        intTotal = intTotal Mod 25
        dimeChange = intTotal \ 10
        intTotal = intTotal Mod 10
        nickelChange = intTotal \ 5
        intTotal = intTotal Mod 5
        pennyChange = intTotal \ 1
        intTotal = intTotal Mod 1

        'display total amounts in controls
        Me.xChangeLabel.Text = Convert.ToString(changeDue)
        Me.xDollarLabel.Text = Convert.ToString(dollarChange)
        Me.xQuarterLabel.Text = Convert.ToString(quarterChange)
        Me.xDimeLabel.Text = Convert.ToString(dimeChange)
        Me.xNickelLabel.Text = Convert.ToString(nickelChange)
        Me.xPennyLabel.Text = Convert.ToString(pennyChange)

        Me.xChangeLabel.Text = Format(changeDue, "currency")

        'send focus to the clear form
        Me.xOwedTextBox.Focus()
    End Sub
End Class


User is offlineProfile CardPM
+Quote Post


CamoDeveloper

RE: Change Code

3 Jul, 2009 - 04:43 PM
Post #2

D.I.C Head
Group Icon

Joined: 12 Jun, 2009
Posts: 204



Thanked: 12 times
Dream Kudos: 200
My Contributions
Well, what's it suppose to do and what is it doing?

~Camo
User is offlineProfile CardPM
+Quote Post

mark.bottomley

RE: Change Code

5 Jul, 2009 - 04:53 PM
Post #3

D.I.C Addict
****

Joined: 22 Apr, 2009
Posts: 780



Thanked: 127 times
My Contributions
You should walk through your code using the debugger to see if it is doing the things you expect.

Generally clear code - better than average for starters!

The problems at a high level are 1) make sure you are reading the values you want to read 2) make sure values you are using are initialized. Stop here if you don't want more detail.







Specifically, amountOwed source and intTotal.











More specifically amountOwed should be Decimal.Parse(Me.xOwedTextBox.Text)
and intTotal should be intTotal = changeDue * 100
User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Change Code

5 Jul, 2009 - 05:02 PM
Post #4

Dyslexics Untie!
Group Icon

Joined: 26 Jul, 2007
Posts: 14,714



Thanked: 501 times
Dream Kudos: 11450
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

User is offlineProfile CardPM
+Quote Post

colemand

RE: Change Code

5 Jul, 2009 - 06:10 PM
Post #5

New D.I.C Head
*

Joined: 3 Jul, 2009
Posts: 2

It is not giving me an error but when I put in 357 in the number of pennies nothing happens. What it should do is break the pennies down and tell me how many quarters, how many dimes, nickles and dollars.




QUOTE(mark.bottomley @ 5 Jul, 2009 - 04:53 PM) *

You should walk through your code using the debugger to see if it is doing the things you expect.

Generally clear code - better than average for starters!

The problems at a high level are 1) make sure you are reading the values you want to read 2) make sure values you are using are initialized. Stop here if you don't want more detail.







Specifically, amountOwed source and intTotal.











More specifically amountOwed should be Decimal.Parse(Me.xOwedTextBox.Text)
and intTotal should be intTotal = changeDue * 100


User is offlineProfile CardPM
+Quote Post

mark.bottomley

RE: Change Code

6 Jul, 2009 - 06:28 AM
Post #6

D.I.C Addict
****

Joined: 22 Apr, 2009
Posts: 780



Thanked: 127 times
My Contributions
I assume that the input textboxes get a currency value - e.g. owed contains say 7.44 and paid contains 10.00. Your initial code was reading the wrong input i.e. amountOwed = Decimal.Parse(Me.xChangeLabel.Text) should be amountOwed = Decimal.Parse(Me.xOwedTextBox.Text). The other problem is that the calculation for changeDue is correct, but nothing is ever assigned to IntTotal so no coin values are selected. It needs to be initialized to pennies so you make IntTotal = ChangeDue * 100.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 12:57AM

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