如何使用visual basic算术运算

时间:2011-02-07 13:10:57

标签: .net vb.net operators math currency

你如何在视觉基础上使用金钱我知道我必须设置镍币并除以5而我想要对数字有另一种表达方式。然后我想确定我会留下什么样的改变,这样我就可以确定我有多少便士。感谢所有看起来的人。

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 =

编辑:有人可以向我暗示我做错了什么我没有得到任何输出谢谢...提示可以是示例检查这一行。谢谢

    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)

1 个答案:

答案 0 :(得分:3)

为了找到变化,我建议您实际使用Math.DivRem,它将立即回答相关问题:

  • 我可以使用多少这枚硬币?
  • 之后我还有多少时间可以处理?

编辑:如果你真的想坚持算术,我会计算你还需要用多少钱。例如:

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

这样你就不必担心以前的结果了。