5 Replies - 378 Views - Last Post: 06 July 2009 - 07:28 AM Rate Topic: -----

#1 colemand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-July 09

Change code

Posted 03 July 2009 - 05:41 PM

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.
'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



Is This A Good Question/Topic? 0
  • +

Replies To: Change code

#2 CamoDeveloper  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 20
  • View blog
  • Posts: 250
  • Joined: 12-June 09

Re: Change code

Posted 03 July 2009 - 05:43 PM

Well, what's it suppose to do and what is it doing?

~Camo
Was This Post Helpful? 0
  • +
  • -

#3 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Change code

Posted 05 July 2009 - 05: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
Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1619
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Change code

Posted 05 July 2009 - 06:02 PM

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

Was This Post Helpful? 0
  • +
  • -

#5 colemand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-July 09

Re: Change code

Posted 05 July 2009 - 07:10 PM

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.




View Postmark.bottomley, on 5 Jul, 2009 - 04:53 PM, said:

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

Was This Post Helpful? 0
  • +
  • -

#6 mark.bottomley  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 175
  • View blog
  • Posts: 990
  • Joined: 22-April 09

Re: Change code

Posted 06 July 2009 - 07:28 AM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1