該子程序將在Button1
被按下時運行。這將顯示兩個隨機數供用戶乘。 (顯示在TB2和TB3中)
現在,只要顯示這些數字(並且在用戶有機會輸入任何答案之前),程序將檢查TB4中的值。這是空的,並在嘗試解析時引發錯誤。
嘗試將其分解爲2個子程序,其中包含2個按鈕:一個顯示新問題的按鈕和一個檢查答案的按鈕。
編輯:添加代碼。 (注:我寫這個寫意 - 不要知道它是否會編譯或不...剛剛得到的總體思路注按鈕名稱。)
//This routine sets up the problem for the user.
private void btnGenerateProblem_Click(object sender, EventArgs e) {
//Get 2 random factors
int x = Randomnumber.Next(12);
int z = Randomnumber.Next(12);
//Display the two factors for the user
textBox2.Text = x.ToString();
textBox3.Text = z.ToString();
}
//This routine checks the user's answer, and updates the "correct count"
private void btnCheckAnswer_Click(object sender, EventArgs e) {
//Get the random numbers out of the text boxes to check the answer
int x = int.Parse(textBox2.Text);
int z = int.Parse(textBox3.Text);
//Compute the true product
int s = x * z;
//Does the true product match the user entered product?
if (s == int.Parse(textBox4.Text)) {
correct++;
numbercorrect.Text = correct.ToString();
}
}
在btnCheckAnswer_Click
開頭添加驗證碼。
我不明白的問題是 –
我不能在此刻發現任何明顯的問題是什麼。它應該做什麼? –
我真的不明白問題是什麼。你應該告訴我們你當前的代碼發生了什麼,你期待的是什麼,以及它們有什麼不同。 – caesay