-1

我正在为学校做作业,我有点迷茫。GUI 应该有一个文本输入框,您可以在其中输入 SAT 分数,然后它将该分数转换为 ACT 分数并将该 ACT 分数显示到一个文本框中,然后在另一个文本框中说明该分数是否足够高。

根据 SAT 是否属于这些数字,将 SAT 分数转换为 ACT 分数。我不明白如何编写它来找出 SAT 输入分数在 ACT 方面的位置并将其显示到该文本框......

    SAT score > 1600    = ACT score 37 (high enough)
    SAT score from 1560-1590    = ACT score 36 (high enough)
    SAT score from 1510-1550    = ACT score 35 (high enough)
    SAT score from 1460-1500    = ACT score 34 (high enough)
    SAT score from 1410-1450    = ACT score 33 (too low)
    SAT score from 1360-1400    = ACT score 32 (too low)
    SAT score < 1350    = ACT score 31 (too low)

此外,我们必须编写一个 try/catch 来确保输入的是整数而不是其他任何内容。那部分我理解。

到目前为止,这是我的代码,没有任何错误。

    private void convertButton_Click(object sender, EventArgs e)
    {



        try
        {
            double satscore;
            satscore = Convert.ToDouble(satScoreTextBox.Text);
        }
        catch
        {
            MessageBox.Show("Invalid input, value must be numeric");
            satScoreTextBox.Focus();
            satScoreTextBox.SelectAll();
        }



    }

    private void exitButton_Click(object sender, EventArgs e)
    {
        this.Close();
    }


}

}

谢谢,任何帮助表示赞赏!

4

2 回答 2

0
private void convertButton_Click(object sender, EventArgs e)
{
    try
    {
        String message="";
        double satscore;
        int actscore=0;
        satscore =Double.Parse(satScoreTextBox.Text);
        if(satscore>1600)
        {
            actscore=37;
            message="ACT score "+actscore+" (high enough)";
        }
        else if(satscore>=1560&&satscore<=1590)
        {
            actscore=36;
            message="ACT score "+actscore+" (high enough)";
        }
        else if(satscore>=1510&&satscore<=1550)
        {
            actscore=35;
            message="ACT score "+actscore+" (high enough)";
        }
        else if(satscore>=1460&&satscore<=1500)
        {
            actscore=34;
            message="ACT score "+actscore+" (high enough)";
        }
        else if(satscore>=1410&&satscore<=1450)
        {
            actscore=33;
            message="ACT score "+actscore+" (too low)";
        }
        else if(satscore>=1360&&satscore<=1400)
        {
            actscore=32;
            message="ACT score "+actscore+" (too low)";
        }
        else
        {
            actscore=31;
            message="ACT score "+actscore+" (too low)";
        }
    }
    catch
    {
        MessageBox.Show("Invalid input, value must be numeric");
        satScoreTextBox.Focus();
        satScoreTextBox.SelectAll();
    }
}
于 2013-04-23T20:37:26.733 回答
0

为什么不为此使用一些 if 语句?(另外,你以为你说的是​​整数吗?你为什么使用双精度数?)我认为你下次在问这样的问题之前应该做更多的研究......

 private void convertButton(object sender, EventArgs e)
 {
     try
        {
            int satScore;
            satScore = Int32.Parse(satScoreTextBox.Text);
            checkSatScore(satScore);
        }
        catch
        {
            MessageBox.Show("Invalid input, value must be numeric");
            satScoreTextBox.Focus();
            satScoreTextBox.SelectAll();
        }
 }

 private void checkSatScore(int satScore)
 {
     int actScore;

     if(satScore > 1600)
         actScore = 37;
     else if (satScore > 1560)
         actScore = 36;
     else if (satScore > 1510)
         actScore = 35;
     else if (satScore > 1460)
         actScore = 34;
     else if (satScore > 1410)
         actScore = 33;
     else if (satScore > 1360)
         actScore = 32;
     else
         actScore = 31

     if(actScore > 33)
         satScoreTextBox.Text = "ACT Score " + actScore + "(high enough)";
     else
         satScoreTextBox.Text = "ACT Score " + actScore + "(too low)";

 }
于 2013-04-23T20:43:24.337 回答