|
-
April 3rd, 2002, 04:40 AM
#1
Help, Please... VB Question..
Hey.. I'm stuck.. I'm a little rusty with my VB.. And I have a review program.. I need to do some Mod-type function..
I have two numbers let's say.. 6.43 and 6.57... When I divide by 1 (using "\" instead of "/").. I get 6 for the first and 7 for the second.. I need to get 6 for both of them because I am using it's remainder to divide again.. It's a change dispensing loop by the way.... First 1's, then .25's, then .10's etc.. How do I get the Mod function to round down?
-
April 3rd, 2002, 04:47 AM
#2
I'm not too familiar with VB, but I have written similar programs before in various languages. My recommendation would to be pull the whole number off (that's how many 1's you'd get), and then work on the decimal from there. The problem has to do with rounding the floating-point to an integer (the second gets rounded up to 7 because it's greater than 6.4999...). Just my opinion.
AJ
-
April 3rd, 2002, 05:01 AM
#3
This is the kludgiest, quickest fix I could think of:
Code:
if (number \ 1) > number then number = (number \ 1) - 1
else number = number \ 1
Hope this helps .
OpenBSD - The proactively secure operating system.
-
April 3rd, 2002, 05:08 AM
#4
Pretty Simple!
int(6.43) = 6
int(6.57) = 6
The Fonction INT(Number) will give you everything before the points. All the decimal are trash out! 
Hope it help.
-
April 3rd, 2002, 06:31 AM
#5
Unfortunately, no.. That did not help.. I need to write a program.. Which Counts out the change that I would give out to a customer after a purchase.. IN this format: # of Singles, # of Quarters, # of Dimes, etc.. This is what I have so far.. If you copy this into VB and run it.. You'll see my problem.. IE: YOu wouldn't give out 4 dollars if the change is only 3.74.. You would give out 3 and then 2 quarters, 2 dimes, 0 nickels and 4 pennies.. See my dilema now? Someone please help..
Private Sub cmdExe_Click()
Dim Cash As Single, Cost As Single, Change As Single
Dim Error As String
Dim S As Integer, Q As Integer, D As Integer, N As Integer, P As Integer
Open "c:/my documents/money.txt" For Input As #1
picOut.FontBold = True
picOut.FontUnderline = True
picOut.Print "CASH"; Spc(5); "COST"; Spc(5); "CHANGE"; Spc(5); "DOLLARS"; Spc(5); "QUARTERS"; Spc(5); "DIMES"; Spc(5); "NICKELS"; Spc(5); "PENNIES"
picOut.FontBold = False
picOut.FontUnderline = False
Do While Not EOF(1)
Input #1, Cash, Cost
If (Cash < Cost) Then
Error = "------------------------- You Do Not Have Enough Money to Make the Purchase -------------------------"
picOut.Print Tab(3); FormatCurrency(Cash); Tab(16); FormatCurrency(Cost); Tab(33); Error
Else
Change = Cash - Cost
S = (Change \ 1)
Q = (Change / 0.25) - S * 4
D = (Change / 0.1) - Q * 2.5
N = (Change / 0.05) - D * 2
P = (Change / 0.01) - N * 5
picOut.Print Tab(3); FormatCurrency(Cash); Tab(16); FormatCurrency(Cost); Tab(33); FormatCurrency(Change, 2); Tab(54); S; Tab(74); Q; Tab(89); D; Tab(106); N; Tab(123); P
End If
Loop
Close #1
End Sub
Thanks again
-
April 3rd, 2002, 11:26 PM
#6
-
April 4th, 2002, 07:34 PM
#7
Phew!
Thank you so much! I can't believe it was that simple.. Maybe I was just thinking that I had to do more.. Once again.. That helped so much, thanks again!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|