3 Replies - 510 Views - Last Post: 06 October 2012 - 01:59 AM Rate Topic: -----

#1 NewbieatVb6  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-October 12

An Error with my change maker Program

Posted 04 October 2012 - 06:19 PM

Hey im new to this forum. Im in grade 10 taking programming for the first time and after 2 weeks of mindf***ing stuff I was given our first project making a change maker basically what its supposed to do is you place you amount of money ex.) 15.65 and its supposed to convert that amount to the least amount of change so it'll be like 7 toonies 1 loonie 2 quarters 1 dime and 1 nickel. After constatly bugging my teacher shes given me a hint were you can't divide decimals and x by 100 to remove any decimal after getting decently far I think? I was stumped when my program didnt want me to do what it wanted to do. I have basic knowlage that Mod means the remainder and \ is like interger division i think it means that it rounds what it divised or something and / is regular. I know you don't do homework but can you give me more hints or fix my error? Don't laugh please im a programming virgin

 Dim num1 As Double
Dim num2 As Double
Dim num3 As Double
Dim num4 As Double
Dim num5 As Double
Dim num6 As Double
Dim num7 As Double
Dim num8 As Double
Dim num9 As Double

Private Sub Command1_Click()
num1 = Text1
num2 = (num1 * 100)
num3 = (num2 \ 200)
num4 = (num2 Mod 200)
num5 = (num4 Mod 25)

Label1.Caption = num3
Label2.Caption = num4
Label3.Caption = num5

End Sub



btw my error is that num3 too label1 displays how many toonies and num4 to label2 is supposed to display how many loonies but it doesnt and num5 to label3 is supposed to display how many quarters and so on thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: An Error with my change maker Program

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,767
  • Joined: 26-March 09

Re: An Error with my change maker Program

Posted 05 October 2012 - 03:42 AM

You need to use an extra function as well as reviewing your maths.

1. Use the INT function to round your number, so for your toonies (whatever they are), you would use INT(1565 / 200) which equals 7.

2. You then need to take into account what you've already used, so in this case, you used 7 toonies, or 1400 of your 1565 to pay out. So to calculate your next lower denomination, loonies (I feel like one using these terms), you would use a combination of the MOD function (this gives you the remainder) and the INT function to round again, so something like int((1565 mod 200)/100), which will give you 1 loonie.

See if you can use the above advice to complete your project.

Once you do, post back your code for others to see and reference in future.
Was This Post Helpful? 0
  • +
  • -

#3 NewbieatVb6  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 04-October 12

Re: An Error with my change maker Program

Posted 05 October 2012 - 04:30 PM

I took your advice and i came up with this but it still doesnt work :S

Dim num1 As Double
Dim num2 As Double
Dim num3 As Double
Dim num4 As Double
Dim num5 As Double
Dim num6 As Double
Dim num7 As Double


Private Sub Command1_Click()
num1 = (Text1 * 100)
num2 = Int(num1 Mod 200)
num3 = Int((num1 Mod 200) / 100)
num4 = Int(((num1 Mod 200) / 100) / 25)
num5 = Int((((num1 Mod 200) / 100) / 25) / 10)
num6 = Int(((((num1 Mod 200) / 100) / 25) / 10) / 5)
num7 = Int((((((num1 Mod 200) / 100) / 25) / 10) / 5) / 1)

Label1.Caption = num2
Label2.Caption = num3
Label3.Caption = num4
Label4.Caption = num5
Label5.Caption = num6
Label6.Caption = num7



What am i doing wrong D:
Was This Post Helpful? 0
  • +
  • -

#4 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,767
  • Joined: 26-March 09

Re: An Error with my change maker Program

Posted 06 October 2012 - 01:59 AM

Try reading my post again..... You missed out stage 1 and tried to use the Mod function straight off.

Also, to make your code easier to read, instead of using num1 to numX, try giving them meaningful names and using a naming convention. I thought that might be something they taught in the classes. Naming conventions usually combine a description of the datatype and a meaningful variable name.

So, for example:

' We use dbl to represent a Double, we would use int to represent and Integer and so on.
Dim dblToonies as double
dim dblLoonies as double
dim dblQuarters as double
etc.


This way it makes it easier for yourself and others to figure out what your trying to do. If I look at your code at the moment, I have no idea what num6 is and therefore, I have no idea what your calculation should be (slight exaggeration, but you get the picture).

So basically, think about the maths side of it. Write it down on a bit of paper if necessary (i.e.: A basic program design), then look at your code again, using the advice given.

Please don't think I'm being harsh with you, it's just easier to learn if you get there yourself with advice, than me just writing it for you.

Good luck
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1