开发者

How to use arithmetic operations for visual basic

开发者 https://www.devze.com 2023-02-08 19:58 出处:网络
How do you use money in visual basic I know that I have to set nickels and divide by 5 and I am suppose to have another expression to the number. Then i am suppose to determine what change i would hav

How do you use money in visual basic I know that I have to set nickels and divide by 5 and I am suppose to have another expression to the number. Then i am suppose to determine what change i would have left so that way i can determine how many pennies I have. Thanks to all who looks.

Dim change As Integer
Dim amountused As Integer
Dim quarters As Integer
Dim dimes As Integer
Dim nickels As Integer
Dim pennies As Integer
Console.WriteLine("Please enter your amount here")
amountused = Console.ReadLine()
Console.WriteLine("change= 100-amount used")
Console.WriteLine(quarters = change \ 25)
Console.WriteLine(dimes = (change - quarters * 25) / 10)
Console.WriteLine(nickels = change \ 5)
Console.WriteLine(pennies =

edit:Can someone hint to me what I am doing wrong I don't get nothing for output Thanks... The hint could be example check this line. Thanks

    Dim change As Integer
    Dim amountused As Integer
    Dim quarters As Integer
    Dim dimes As Integer
    Dim nickels As Integer
    Dim pennies As Integer
    Console.WriteLine("Please enter your amount here")
    amountused = Console.ReadLine()
    change = ("100 - amountused")
    quarters = change \ 25
    Console.WriteLine("Quarters:{0}", quarters)
    change = change - (quarters * 25)
    dimes = change \ 10
    Console.WriteLine("Dimes:开发者_开发技巧 {0}", quarters)
    change = change - (dimes * 10)
    nickels = change \ 5
    change = change - (nickels * 5)
    Console.WriteLine("nickels: {0}", quarters)
    change = pennies \ 1
    change = change - (pennies * 1)
    Console.WriteLine("pennies:{0}", pennies)


For finding change, I would suggest you actually use Math.DivRem which will answer both the relevant questions at once:

  • How many of this coin can I use?
  • How much will I still left to deal with afterwards?

EDIT: If you really want to stick to arithmetic, I'd keep a count of how much you still need to use up. For example:

quarters = change \ 25
Console.WriteLine("Quarters: {0}", quarters)
change = change - (quarters * 25)

dimes = change \ 10
Console.WriteLine("Dimes: {0}", quarters)
change = change - (dimes * 10)
... etc

That way you don't need to keep worrying about your previous results.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号