Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre>>/**I have a table named Math, with questions and 4 answers for each >question..and when the student answers correctly I want to go to the next >question. I did something(I will attached the code) but the application >never go to the next question... I dont know how to do that, heeeelp?**/

C#
<pre>    
 

public Test ()
		{
			InitializeComponent ();
            questions = App.Database.GetQuestions();
            size = questions.Count;
            Debug.WriteLine(size);
            Debug.WriteLine("==============================");
            Debug.WriteLine("==============================");
            Debug.WriteLine(i);
            Debug.WriteLine(size);
            Debug.WriteLine("==============================");
           if (i < size)
            {
                titleLabel.Text = questions[i].question;
                one.Text = questions[i].answer1;
                two.Text = questions[i].answer2;
                three.Text = questions[i].answer3;
                four.Text = questions[i].answer4;
                i++;
            }
            else
                titleLabel.Text = "FMM";
            //i++;
        }
//:(
        private void corect(object sender, EventArgs e)
        {
            if(i < size)
            {
                if((sender as Button).ClassId == questions[i].correct)
                {
                   
                    titleLabel.Text = questions[i].question;
                    one.Text = questions[i].answer1;
                    two.Text = questions[i].answer2;
                    three.Text = questions[i].answer3;
                    four.Text = questions[i].answer4;
                   i++;
                }
                else
                    DisplayAlert("Firar", "Mai incearca", "OK");
                
            }
            else
                DisplayAlert("Felicitari", "Urmatoarea intrebare", "OK");
           
        }



What I have tried:

I made the code for know what is the right answer
Posted
Updated 7-Apr-19 6:10am
Comments
Richard MacCutchan 7-Apr-19 11:07am    
You are using the variable i But you never set its value.
[no name] 7-Apr-19 11:13am    
No chance to vote a 5 for this here.

1 solution

If the answer is correct, increment i, then set up the next question.

However, in your case, you are incrementing i AFTER setting up the next question; which has the affect of setting up the LAST question again (in the button handler).

You are also incrementing i in the "constructor" which means you'll always get a false unless the NEXT answer matches the CURRENT question.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900