Help neede please

[b][red]This message was edited by Marc_H at 2006-2-15 6:54:46[/red][/b][hr]
[b][red]This message was edited by Marc_H at 2006-2-15 6:54:27[/red][/b][hr]
I'm currently doing Visual basics in college and I'm doing a project where as I've to Create a program for a bank ATM. I'm looking for the code I need To determine that withdrawal amount is in multiples of 10. e.g. I've been trying things like "If Not withdrawal mod 10 <> Integer then msgbox etc.
(divide withdrawal amount by 10 = a whole number. and so on but it still doesn't work.) Help Me Please.




Comments

  • : [b][red]This message was edited by Marc_H at 2006-2-15 6:54:46[/red][/b][hr]
    : [b][red]This message was edited by Marc_H at 2006-2-15 6:54:27[/red][/b][hr]
    : I'm currently doing Visual basics in college and I'm doing a project where as I've to Create a program for a bank ATM. I'm looking for the code I need To determine that withdrawal amount is in multiples of 10. e.g. I've been trying things like "If Not withdrawal mod 10 <> Integer then msgbox etc.
    : (divide withdrawal amount by 10 = a whole number. and so on but it still doesn't work.) Help Me Please.

    Integer is a datatype, not a variable, you can't use it in an expression like you're doing.

    If you want a multiple of ten, then the result of the mod 10 operation should be zero (no remainder after dividing by ten)

    [code]
    If lngWithdrawalAmount Mod 10 = 0 Then
    'Value is a multiple of ten
    Else
    'Value is NOT a multiple of ten
    End If
    [/code]


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

  • Typically responses towards helping w/ school homework is not honored in these forums. However, your task is a little tricky, so I do not feel guilty helping you:

    To find multiples of something or to skip every something, you use the Mod operator:

    [code]
    Dim amount As Double

    amount = 31.00

    If amount Mod 10 = 0 Then
    MsgBox "Good"
    Else
    MsgBox "Bad"
    End If
    [/code]

    The result of Mod will return zero, if the number on the left is evenly divisible by the number on the right.

    Now, the trick part. What happens when you use the same test above, about on the amount 30.27.

    [code]
    Dim amount As Double

    amount = 30.27

    If amount Mod 10 = 0 Then
    MsgBox "Good"
    Else
    MsgBox "Bad"
    End If
    [/code]

    Something unexpected happens. It indicates that this number is evenly divisible by 10, which we know is not true. What gives? Well the Mod operator only works with integers. Both numbers on the left and right side of the Mod operator gets converted into an Integer, so even though the number is 30.27, the Mod operator treats it as 30.

    To get around this you can use this code ...

    [code]
    Dim amount As Double

    amount = 30.27

    If amount - Fix(amount) = 0 Then
    MsgBox "Good"
    Else
    MsgBox "Bad"
    End If
    [/code]

    The Fix() function completely removes the decimal portion of a number.

    Now that we are armed w/ these two weapons, we combine it into our final algorithm:

    [code]
    Dim amount As Double

    amount = 31.77

    If amount - Fix(amount) = 0 And amount Mod 10 = 0 Then
    MsgBox "Good"
    Else
    MsgBox "Bad"
    End If
    [/code]

    You should be able to adapt this to your needs.

  • : Typically responses towards helping w/ school homework is not honored in these forums. However, your task is a little tricky, so I do not feel guilty helping you:

    Helping with homework is fine if the OP shows they've made an effort and have specific questions/problems and need advice. Asking people to do your homework for you is just lame and is justifiably ignored by most people.


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories