当松鼠聚在一起参加聚会时,它们喜欢吃橡子。松鼠派对成功的前提是橡子的数量在 40 到 60 之间,包括周末,在这种情况下,橡子的数量没有上限。编写一个程序,找出聚会的时间和有多少橡子。如果派对在规则范围内,则返回“Good Party”,如果橡子数量错误,则返回“Terrible Party”。
我已经完成了橡子数量的部分,但在周末部分挣扎,我也是新手 这是我的代码
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int acorns = int.Parse(textBox1.Text);
if (acorns >= 40 && acorns <= 60)
{
MessageBox.Show("Good Party");
}
else
{
MessageBox.Show("Terrible Party");
}
}
}
只需检查您工作日期的星期几。这里我使用系统日期
private void button1_Click(object sender, EventArgs e)
{
int acorns = int.Parse(textBox1.Text);
if (acorns >= 40 && (System.DateTime.Today.DayOfWeek == DayOfWeek.Saturday || System.DateTime.Today.DayOfWeek == DayOfWeek.Sunday || acorns <= 60))
{
MessageBox.Show("Good Party");
}
else
{
MessageBox.Show("Terrible Party");
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句