GUI的更多问题

时间:2013-04-23 20:22:21

标签: c# user-interface

我正在为学校工作,我有点失落。 GUI应该有一个文本输入框,您可以在其中输入SAT分数,然后将该分数转换为ACT分数,并将该ACT分数显示在文本框中,然后在另一个文本框中显示该分数是否足够高。 / p>

根据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();
    }


}

}

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

2 个答案:

答案 0 :(得分: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();
    }
}

答案 1 :(得分: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)";

 }