关于GUI的更多问题
本文关键字:问题 GUI 关于 | 更新日期: 2023-09-27 18:10:39
我正在做学校的作业,我有点迷路了。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();
}
}
}
谢谢你,任何帮助都是感激的!
为什么不使用几个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)";
}
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();
}
}