我正在尝试创建一个检查答案按钮。我还没有学会如何使用方法,所以我不能在这里使用它们。我首先需要检查数学运算是减法还是加法,然后再从那里开始。Visual studio未检测到任何错误,但当我运行程序并尝试检查输入的答案时,我收到一个错误,告诉我发生了未处理的异常,并且输入字符串的格式不正确。我有一种感觉,问题出在我的int-lblMath上,但我不知道如何检查lbl中的值。
{
int First = int.Parse(lblFirst.Text);//The first number in the math equation
int Second = int.Parse(lblSecond.Text);//The second number in the math equation
int UserAnswer = Convert.ToInt32(txtAnswer.Text);//The users answer to math question
int lblMath = int.Parse(lblMathType.Text);//Whether the symbol is + or -
if(lblMath == '+')
{
int AnswerAdd = First + Second;
//Answer is addition
if(UserAnswer == AnswerAdd)
{
MessageBox.Show("Correct");
}
else if(UserAnswer != AnswerAdd)
{
MessageBox.Show("Wrong Answer");
}
}
else if (lblMath == '-')
{
int AnswerSub = First - Second;
//Answer is subtraction
if(UserAnswer == AnswerSub)
{
MessageBox.Show("Correct");
}
else if (UserAnswer != AnswerSub)
{
MessageBox.Show("Wrong Answer");
}
}