C # Method and variable call

-1

I'm doing a C + + in C #, I've done the question methods but when it comes to verifying the correct alternatives I'm not writing the punctuation at the variable points, what am I doing wrong?

using System;
using System.Windows.Forms;

namespace Quiz
{
    public partial class QuizComidas : Form
    {
        private int pontos = 0;

        public QuizComidas()
        {
            InitializeComponent();
     
        }
        
        private void Pergunta2()
        {
            LblQuestao.Text = "Questão 2";
            lblPergunta.Text = "Em que Pais foi inventada a feijoada?";
            lblResposta.Text = "";

            btbAlt1.Text = "Italia";
            btbAlt2.Text = "Brasil";
            btbAlt3.Text = "Argentina";
            btbAlt4.Text = "Portugal";

            btbAlt1.Checked = false;
            btbAlt2.Checked = false;
            btbAlt3.Checked = false;
            btbAlt4.Checked = false;

            if (btbAlt4.Checked == true)
            {

                pontos += 1;
                pontos++;
            }

        } 

        private void Pergunta3()
        {
            LblQuestao.Text = "Questão 3";
            lblPergunta.Text = "O acarajé foi inventado aonde?";
            lblResposta.Text = "";

            btbAlt1.Text = "Bahia";
            btbAlt2.Text = "Maranhão";
            btbAlt3.Text = "São Paulo";
            btbAlt4.Text = "Salvador";

            btbAlt1.Checked = false;
            btbAlt2.Checked = false;
            btbAlt3.Checked = false;
            btbAlt4.Checked = false;

            if (btbAlt2.Checked == true)
            {

                pontos = pontos + 1;
            }
        }

        private void Pergunta4()
        {
            LblQuestao.Text = "Questão 4";
            lblPergunta.Text = "A Caipirinha tem "+"\n"+
                                "origem de qual estado brasileiro?";
        

            btbAlt1.Text = "Mato Grosso";
            btbAlt2.Text = "Acre";
            btbAlt3.Text = "São Paulo";
            btbAlt4.Text = "Rio Grande Do Sul";

            btbAlt1.Checked = false;
            btbAlt2.Checked = false;
            btbAlt3.Checked = false;
            btbAlt4.Checked = false;

            if (btbAlt3.Checked == true)
            {

                pontos = pontos + 1;
            }
        }

        private void Pergunta5()
        {
            LblQuestao.Text = "Questão 5";
            lblPergunta.Text = "Você vai na região Sul do país e come"+"\n"+
                                "uma fruta Bergamota."+"\n"+
                                "Uma Bergamota é o mesmo que:";

            btbAvançar.Text = "Finalizar";
            btbAlt1.Text = "Laranja";
            btbAlt2.Text = "Maça";
            btbAlt3.Text = "Mexerica";
            btbAlt4.Text = "Uva";

            btbAlt1.Checked = false;
            btbAlt2.Checked = false;
            btbAlt3.Checked = false;
            btbAlt4.Checked = false;

            if (btbAlt3.Checked == true)
            {

                pontos = pontos + 1;
            }
        }


        private void lblPergunta_Click(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void btbCorreto_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void QuizComidas_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            
        }

        private void btbAvançar_Click(object sender, EventArgs e)
        {

            if(LblQuestao.Text == "Questão 1")
            {
                Pergunta2();
                

            } 
           
              else  if (LblQuestao.Text == "Questão 2") 
            {
                Pergunta3();
       
            }
                else if(LblQuestao.Text == "Questão 3")
            {
                Pergunta4();
            }
                else if(LblQuestao.Text == "Questão 4")
            {
                Pergunta5();
              
            }
            else if(btbAvançar.Text == "Finalizar")
            {
                MessageBox.Show("Sua Pontuação: "+ pontos, "Pontuação",
             MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            }
            }
            
        }
   
    
asked by anonymous 24.10.2018 / 04:14

1 answer

0

The first problem is that you are checking the response at the same time that you are creating the question. As was said in the Adjair comments.

You should not check the answer in the methods Question1 (), Question2 (), etc ...

These methods should only be responsible for creating the questions.

The second problem is that once you are sharing the answer buttons between all the questions, the correct answer will depend on the current question.

So create a variable called private int respostaCorreta; and in each method of creating the questions, store the button that has the correct answer to this question. For example in method Pergunta2() assign respostaCorreta = 4; to method Pergunta3() assign respostaCorreta = 2; and so on

Resolved this, implement the click events of the four response buttons and verify that the clicked button is the one stored in the responseCorrect variable. If positive increase the points pontos++;

Ex:

 private void radioButton1_CheckedChanged(object sender, EventArgs e)
 {
    if (respostaCorreta == 1)
    {
        pontos++;
    }
 }

 private void radioButton2_CheckedChanged(object sender, EventArgs e)
 {
    if (respostaCorreta == 2)
    {
        pontos++;
    }
 }

and so on.

PS: Check the name of the methods because the controls have a name pattern and other methods (btbAlt1 and radioButton1_CheckedChanged) the method should be called btbAlt1_CheckedChanged

    
24.10.2018 / 14:17