我的任务是创建一个C#windows窗体应用程序,其中包含一个循环,用于输入上限和下限的输入,输出从10开始,在上限之前结束。我的程序不会输出任何内容,我不确定是什么问题。这就是我所拥有的:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Loops
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int lowerBounds, upperBounds, num;
private void TextBoxUpperBounds_TextChanged(object sender, EventArgs e)
{
upperBounds = Convert.ToInt32(Console.ReadLine());
}
private void BtnOutputValues_Click(object sender, EventArgs e)
{
for (num = lowerBounds; num < upperBounds; num++)
{
if (num % 10 == 0)
{
MessageBox.Show(num.ToString());
}
else { }
}
}
private void TextBoxLowerBounds_TextChanged(object sender, EventArgs e)
{
lowerBounds = Convert.ToInt32(Console.ReadLine());
}
}
}
答案 0 :(得分:0)
你的代码只输出低于上限的10的倍数。
使你的代码输出下限和上限之间的数字,大于10,你应该在循环中使用:
for (num = lowerBounds; num < upperBounds; num++)
{
if (num >10 )
{
MessageBox.Show(num.ToString());
}
else { }
}
答案 1 :(得分:0)
atomSmasher是完全正确的。以下代码完全符合我的要求:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Loops
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int lowerBounds, upperBounds, num;
private void TextBoxUpperBounds_TextChanged(object sender, EventArgs e)
{
upperBounds = Convert.ToInt32(textBoxUpperBounds.Text);
}
private void BtnOutputValues_Click(object sender, EventArgs e)
{
for (num = lowerBounds; num < upperBounds; num++)
{
if (num % 10 == 0)
{
MessageBox.Show(num.ToString());
}
else { }
}
}
private void TextBoxLowerBounds_TextChanged(object sender, EventArgs e)
{
lowerBounds = Convert.ToInt32(textBoxLowerBounds.Text);
}
}
}