我必须使用字符串数组创建一个测验,并且会显示一个运行分数,每个正确答案都会加一分,每个错误答案都会减一分。我的第一个问题工作正常,我只是不知道如何为下一个问题做。我只有一个提交按钮,所以第一个问题的所有代码都连接到该按钮。我该如何做到这一点,当您提交第二个答案时,它会告诉您正确然后继续?有人告诉我 for 循环可以很好地处理这个问题,但我不知道如何实现它。
int score = 0;
int i = -1;
int a = 0;
string[] questions = new string[] {
"What is 9 cubed?",
"What is 6+3?",
"What type of animal is tuna sandwiches made from?",
"What is 18 backwards?" };
string[] answers = new string[] {
"9", "81", "729", "2", "4", "2",
"9", "1", "zebra", "aardvark",
"fish", "gnu", "31",
"81", "91", "88" };
private void btnStart_Click(object sender, EventArgs e)
{
if (i < questions.Length)
i++;
//txtScore.Text = score;
lblQuestion.Text = questions[i];
radA.Text = answers[a];
a++;
radB.Text = answers[a];
a++;
radC.Text = answers[a];
a++;
radD.Text = answers[a];
a++;
btnStart.Visible = false;
btnStart.Enabled = false;
btnSubmit.Visible = true;
btnSubmit.Enabled = true;
}
private void btnSubmit_Click(object sender, EventArgs e)
{
{
if (i == 0 && radB.Checked)
{
MessageBox.Show("Correct");
score++;
txtScore.Text = Convert.ToString(score);
btnSubmit.Enabled = false;
btnSubmit.Visible = false;
btnStart.Visible = true;
btnStart.Enabled = true;
btnStart.Text = "Next";
}
else
{
MessageBox.Show("Incorrect");
score--;
}