Penny for Pay问题 [英] Penny for Pay question
问题描述
我的编程课有问题。一个人每天得到报酬,第一天是1便士,第二天是2便士,第三天是4便士,第五天是8便士,等等每天加倍。我写了下面的代码,但是我遇到了问题。当我放入1天它告诉我2便士而不是1.我相信这是一个简单的解决方案,但我的大脑是炸,我忽略它。
这是我的代码:
I have a problem in my programming class. A person gets paid daily, day one is 1 penny, day two is 2 pennies, day three is 4 pennies, day five is 8 pennies and so on doubling each day. I wrote the following code but am having an issue with out put. When I put in 1 day it tells me 2 pennies instead of 1. I am sure this is an easy fix but my brain is fried and I am overlooking it.
Here is my code:
Public Class Form1
Private Sub calculateButton_Click(sender As Object, e As EventArgs) Handles calculateButton.Click
Dim intDays As Integer
intDays = 1
Dim decPennies As Decimal
decPennies = 0.01
For intDays = 1 To cboDays.Text
decPennies = decPennies * 2
Next intDays
ansLabel.Text = decPennies.ToString("C")
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For intDays = 1 To 20
cboDays.Items.Add(intDays)
Next
End Sub
End Class
任何帮助都将是非常感谢。
Any help would be greatly appreciated.
推荐答案
我会替换
I would replace
For intDays = 1 To cboDays.Text
with
with
For intDays = 2 To cboDays.Text
您的程序启动设置为1每天。
要处理0天,你必须检查值0,在这种情况下,结果是0而不是正常程序。尝试自己找到解决方案。
Your program starting setting is 1 day.
To handle 0 day, you have to check for value 0 and in this case say result is 0 instead of doing normal program. Try to find the solution by yourself.
我在VB.NET论坛中解释了什么错误,并给了你一个建议。请不要在多个论坛中发布相同的问题。
I explained what was wrong, and gave you a suggestion, in the VB.NET forum. Please do not post the same question in multiple forums.
这篇关于Penny for Pay问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!