LiveWire Network Peer Answers Peer Support Teen Forums Tech Forums College Forums 444 users online 174647 members 780 active today Advertise Here Sign In
TeenCollegeTechPhotos | Quizzes | LiveSecret | Video | Dictionary | News | FAQ
You have 1 new message.
Emergency Help
Until you sign up you can't do much. Yes, it's free.

Sign Up Now
Membername:
Password:
Already have an account?
Invite Friends
Active Members
Groups
Contests
Moderators
3 online / 38 MPM
Fresh Topics
  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic

visual basic code
whats wrong with it?
Replies: 6Last Post Mar. 10, 2006 6:10pm by squirellplayingtag
Single page for this topic Email Print Favorite
( EarthEmpire )


Enlightened One

Patron
Reply
ok, this thing gives me (once i run the application) weird answers if i input a value with cents value more than 50.. anyone can tell me, what did i do wrong and how should i fix it?
thnx

'Declaring the variables:
  Dim sngChange As Single
  Dim intRChange As Integer
  Dim intThousand As Integer
  Dim intHundred As Integer
  Dim intFifty As Integer
  Dim intTwenty As Integer
  Dim intTen As Integer
  Dim intFive As Integer
  Dim intTwo As Integer
  Dim intOne As Integer
  Dim intQuarter As Integer
  Dim intDime As Integer
  Dim intNickel As Integer
  Dim intCents As Integer

  Private Sub btnCoins_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCoins.Click
      sngChange = Val(Me.txtChange.Text)
      'Introduce the user input control^

      'Enter the formulas for calculating the numbers of coins for each

      intThousand = sngChange \ 1000
      Me.lblThousand.Text = intThousand

      intHundred = (sngChange - 1000 * intThousand) \ 100
      Me.lblHundred.Text = intHundred

      intFifty = (sngChange - 1000 * intThousand - 100 * intHundred) \ 50
      Me.lblFifty.Text = intFifty

      intTwenty = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty) \ 20
      Me.lblTwenty.Text = intTwenty

      intTen = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty - 20 * intTwenty) \ 10
      Me.lblTen.Text = intTen

      intFive = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty - 20 * intTwenty - 10 * intTen) \ 5
      Me.lblFive.Text = intFive

      intTwo = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty - 20 * intTwenty - 10 * intTen - 5 * intFive) \ 2
      Me.lblTwo.Text = intTwo

      intOne = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty - 20 * intTwenty - 10 * intTen - 5 * intFive - 2 * intTwo) \ 1
      Me.lblOne.Text = intOne

      'intRChange is the converter of d.cc format into cc
      intRChange = (sngChange - 1000 * intThousand - 100 * intHundred - 50 * intFifty - 20 * intTwenty - 10 * intTen - 5 * intFive - 2 * intTwo - 1 * intOne) * 100

      intQuarter = intRChange \ 25
      Me.lblQuarter.Text = intQuarter

      intDime = (intRChange - 25 * intQuarter) \ 10
      Me.lblDime.Text = intDime

      intNickel = (intRChange - 25 * intQuarter - 10 * intDime) \ 5
      Me.lblNickel.Text = intNickel

      intCents = (intRChange - 25 * intQuarter - 10 * intDime - 5 * intNickel) \ 1
      Me.lblCents.Text = intCents
  End Sub

  Private Sub txtChange_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtChange.TextChanged
      Me.lblCents.Text = ""
      Me.lblNickel.Text = ""
      Me.lblDime.Text = ""
      Me.lblQuarter.Text = ""
      Me.lblOne.Text = ""
      Me.lblTwo.Text = ""
      Me.lblFive.Text = ""
      Me.lblTen.Text = ""
      Me.lblTwenty.Text = ""
      Me.lblFifty.Text = ""
      Me.lblHundred.Text = ""
      Me.lblThousand.Text = ""
      'If the value entered has been changed, all the outcomes dissappear
  End Sub

  Private Sub mnuExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuExit.Click
      End 'Quits the program
  End Sub
End Class


-------
Remember, remember the 9th of November. Never Refer.
DeviantArt Myspace


7:22 am on Mar. 7, 2006 | Joined April 2005 | 693 Days Active
Join to learn more about EarthEmpire Alberta, Canada | Straight Female | 3970 Posts | 14741 Points
Post from this position was omitted due to content violations
Willowlove


Dairy Product Addict
Reply
Is this VB6?  I am trying to run it using your code but I get an error:"USer type not defined". Did you include all your code(declarations also) in your post?

-------
"The best and most beautiful things in the world cannot be seen or even touched. They must be felt within the heart. "
Helen Keller

10:32 am on Mar. 7, 2006 | Joined April 2005 | 294 Days Active
Join to learn more about Willowlove Tennessee, United States | Lesbian Female | 349 Posts | 3357 Points
squirellplayingtag


Dairy Product Addict

Patron
Reply
I would say you have a rounding issue. I used 1.75 and it came up with 1 two dollar bill. Since this sounds like a homework assignment I'm not going to tell you how to fix it, but it's something to be looked into.

-------
"The most abundant element in the universe is
hydrogen, then second is stupidity."-Harlan Ellison
"What good fortune for our governments that the
people do not think."-Hitler

6:29 pm on Mar. 7, 2006 | Joined Jan. 2003 | 1260 Days Active
Join to learn more about squirellplayingtag Maryland, United States | Straight Male | 6470 Posts | 27140 Points
( EarthEmpire )


Enlightened One

Patron
Reply
squirrelplayingtag,

it used to be homework, but since i already handed it in (weeks ago) and still havent figured it out.. i was just wondering, thanks though, i checked and i didnt see any rounding error places...

-------
Remember, remember the 9th of November. Never Refer.
DeviantArt Myspace


9:08 pm on Mar. 7, 2006 | Joined April 2005 | 693 Days Active
Join to learn more about EarthEmpire Alberta, Canada | Straight Female | 3970 Posts | 14741 Points
squirellplayingtag


Dairy Product Addict

Patron
Reply
I'll look more at it tomorrow night or saturday and get back.

-------
"The most abundant element in the universe is
hydrogen, then second is stupidity."-Harlan Ellison
"What good fortune for our governments that the
people do not think."-Hitler

5:58 pm on Mar. 9, 2006 | Joined Jan. 2003 | 1260 Days Active
Join to learn more about squirellplayingtag Maryland, United States | Straight Male | 6470 Posts | 27140 Points
squirellplayingtag


Dairy Product Addict

Patron
Reply
I rewrote it because I was tired of using the labels so here's what I came up with:
Code:

Public Class Form1

   'Declaring the variables:
   Dim sngAmount As Double
   Dim intRChange As Integer
   Dim intThousand As Integer
   Dim intHundred As Integer
   Dim intFifty As Integer
   Dim intTwenty As Integer
   Dim intTen As Integer
   Dim intFive As Integer
   Dim intTwo As Integer
   Dim intOne As Integer
   Dim intQuarter As Integer
   Dim intDime As Integer
   Dim intNickel As Integer
   Dim intPenny As Integer

   Private Sub btnCoins_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCoins.Click
       sngAmount = Val(Me.txtChange.Text)
       sngAmount = sngAmount * 100
       'Change
       Dim intChange As Integer = CInt(sngAmount Mod 100)
       sngAmount = (sngAmount - intChange) / 100
       'dollars
       'thousand
       intThousand = Math.Floor(sngAmount / 1000)
       ListBox1.Items.Add("Thousands: " & intThousand)
       sngAmount = sngAmount - (intThousand * 1000)
       'hundred
       intHundred = Math.Floor(sngAmount / 100)
       ListBox1.Items.Add("Hundreds: " & intHundred)
       sngAmount = sngAmount - (intHundred * 100)
       'fifty
       intFifty = Math.Floor(sngAmount / 50)
       ListBox1.Items.Add("Fiftys: " & intFifty)
       sngAmount = sngAmount - (intFifty * 50)
       'twenty
       intTwenty = Math.Floor(sngAmount / 20)
       ListBox1.Items.Add("Twentys: " & intTwenty)
       sngAmount = sngAmount - (intTwenty * 20)
       'ten
       intTen = Math.Floor(sngAmount / 10)
       ListBox1.Items.Add("Tens: " & intTen)
       sngAmount = sngAmount - (intTen * 10)
       'five
       intFive = Math.Floor(sngAmount / 5)
       ListBox1.Items.Add("Fives: " & intFive)
       sngAmount = sngAmount - (intFive * 5)
       'one
       ListBox1.Items.Add("Ones: " & sngAmount)

       'Quarter
       intQuarter = Math.Floor(intChange / 25)
       intChange = intChange - (intQuarter * 25)
       ListBox1.Items.Add("Quarters: " & intQuarter)
       'Dimes
       intDime = Math.Floor(intChange / 10)
       intChange = intChange - (intDime * 10)
       ListBox1.Items.Add("Dimes: " & intDime)
       'nickels
       intNickel = Math.Floor(intChange / 5)
       intChange = intChange - (intNickel * 5)
       ListBox1.Items.Add("Nickels: " & intNickel)
       'penny Not really necessary but you had it in there so I'll keep it
       intPenny = intChange
       intChange = 0
       ListBox1.Items.Add("Pennies: " & intPenny)
       
   End Sub

   Private Sub txtChange_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtChange.TextChanged
       ListBox1.Items.Clear()
   End Sub

   Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

   End Sub
End Class


You most definatly have rounding errors, I suggest using Math.Floor on your divisions.

-------
"The most abundant element in the universe is
hydrogen, then second is stupidity."-Harlan Ellison
"What good fortune for our governments that the
people do not think."-Hitler

6:10 pm on Mar. 10, 2006 | Joined Jan. 2003 | 1260 Days Active
Join to learn more about squirellplayingtag Maryland, United States | Straight Male | 6470 Posts | 27140 Points
Single page for this topic Email Print Favorite

Quick Reply

You are signed in as our guest.

Looking for something else?
 

  LiveWire / Technical Forums / Programming & Application Development / Viewing Topic