列表框文本中有没有办法使数字递增?
Is there a way in a listbox text to make the number increment?
日复一日地努力让一分钱的价值翻一番。我的数学计算是正确的,除了列表框中的文本外,它的显示应该是正确的。
已经试过用整型变量自增
pennyDouble = 0.01;
daysInteger = 1;
do
{
millionaireListBox.Items.Add("The value after 1 day(s) is: $" + pennyDouble);
pennyDouble = (2 * pennyDouble);
daysInteger += 1;
}while(condition);
所以我想在列表框中说,
"The value after 1 day(s) is: [=11=].01"
随着白天的增加。所以,
"The value after 2 day(s) is: [=12=].02"
等等。
问题出在您要添加到 millionaireListBox
的字符串中。应该是
millionaireListBox.Items.Add($"The value after {daysInteger} day(s) is: $ {pennyDouble}");
// ^^^^^^^^^^^ Instead of constant 1, you need variable.
即使在 daysInteger
递增之后,您仍在字符串中使用 1。这个常量 1 每次都将相同的值添加到 millionaireListBox
。
您需要在 ListBox
中增加天数,因此使用变量 daysInteger
而不是常量 1。
日复一日地努力让一分钱的价值翻一番。我的数学计算是正确的,除了列表框中的文本外,它的显示应该是正确的。
已经试过用整型变量自增
pennyDouble = 0.01;
daysInteger = 1;
do
{
millionaireListBox.Items.Add("The value after 1 day(s) is: $" + pennyDouble);
pennyDouble = (2 * pennyDouble);
daysInteger += 1;
}while(condition);
所以我想在列表框中说,
"The value after 1 day(s) is: [=11=].01"
随着白天的增加。所以,
"The value after 2 day(s) is: [=12=].02"
等等。
问题出在您要添加到 millionaireListBox
的字符串中。应该是
millionaireListBox.Items.Add($"The value after {daysInteger} day(s) is: $ {pennyDouble}");
// ^^^^^^^^^^^ Instead of constant 1, you need variable.
即使在 daysInteger
递增之后,您仍在字符串中使用 1。这个常量 1 每次都将相同的值添加到 millionaireListBox
。
您需要在 ListBox
中增加天数,因此使用变量 daysInteger
而不是常量 1。