2013-04-23 42 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)"; 

}