2013-04-23 41 views
-1

我正在为学校做作业,而我有点迷路。图形用户界面应该有一个文本输入框,您可以在其中输入SAT分数,然后将该分数转换为ACT分数,并将该ACT分数显示在文本框中,然后说明该分数在另一个文本框中是否足够高。有关GUI的更多问题

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


} 

}

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

+0

所以你试图做转换呢?如果是这样,你尝试了什么(以及发生了什么,为什么它没有工作)?一个巨大的if/else if chain应该是最简单的选择,即使存在一些更灵活/优雅的解决方案。 – Servy 2013-04-23 20:27:11

+0

我还没有尝试过,因为我不知道如何检查哪个范围的数字。我迷路了。迄今为止,我们没有任何实验室或作业。 – user2089370 2013-04-23 20:30:03

+0

@OP StackOverflow不是一个家庭作业解决方案板。至少尝试一下自己,然后尝试发布。与教授或助教一起上课时间可能会更好。 – tyh 2013-04-23 20:31:30

回答

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(); 
    } 
} 
+0

这正是我所期待的。我知道现在该做什么。非常感谢。 – user2089370 2013-04-23 21:22:23

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)"; 

}