Click here to Skip to main content
15,885,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a question for you. I would like to set my WPF application to change my RadioButton only to their own content.I'm trying to create a math quiz where the user could choose one of three options.

I tried the code below.

I prefer to send the whole code here so as not to miss anything (yes, it is badly written but perhaps functional). My problem is that I would like to Radiobutton(firstOption, secondOption, thirdOption)assign values ​​to their content so that one was correct. I would assign values ​​according to what the mark is as in the individual examples( for example the user selects a plus, which is calculated as follows
C#
if (mark.Text == "+")
                    {
                        int total = (firstN + secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }

and one of the options would work out accordingly, with different results being palpable.

But I have no idea how to assign it there.

If anyone has any questions, write me in the comments, I apologize for the combination of languages. I hope it's at least a little obvious what I mean.

Thank you all for any advice.

What I have tried:

C#
List<string> list = new List<string> { "1", "2", "3" };//is there any way to add those options here?
        public void ShuffleText()
        {
            var rand = new Random();
            var shuffledText = list.OrderBy(x => rand.Next(list.Count)).ToList();
            var radioButtons = new[] { firstOption, secondOption, thirdOption };

            for (int i = 0; i < radioButtons.Length; i++)
            {
                radioButtons[i].Content = shuffledText[i];
            }
        }

        private void control_Click(object sender, RoutedEventArgs e)
        {

            timer.Value += 1;
            shiftTimer.Start();
            if (vybOp == 0 || vybOp == 2 || vybOp == 4 || vybOp == 6)//this is enumeration selected operations
            {
                var answerRadioButtons = new RadioButton[] { firstOption, secondOption, thirdOption };
                var correctAnswerButtonFound = false;
                foreach (var answerButton in answerRadioButtons)
                {
                    if (answerButton.IsChecked==true)
                    {

                        if (answerButton.Content == result.Text)
                        {

                            correctAnswerButtonFound = true;
                        }
                    }
                }

                if (correctAnswerButtonFound)
                {
                    shiftTimer.Stop();
                    call.Text = "Correct";
                    count++;
                    numberOfExamples.Text = count.ToString();
                    Random second = new Random();
                    Random first = new Random();

                    int maxFirst = 10;
                    int maxSecond = 10;


                    int secondN = second.Next(2, maxSecond);
                    int firstN = secondN * first.Next(1, maxFirst / secondN);
                    if (mark.Text == "+")
                    {
                        int total = (firstN + secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                     if (mark.Text == "-")
                    {
                        int total = (firstN - secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                     if (mark.Text == "*")
                    {
                        int total = (firstN * secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                     if (mark.Text == "/")
                    {
                        int residue = (firstN % secondN);
                        if (residue == 0)
                        {
                           int total = (firstN / secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();
                        }


                    }


                    timer.Value = 0;
                    shiftTimer.Start();
                }

                else
                {
                    shiftTimer.Stop();
                    call.Text = "Wrong";
                    poch++;//number of error
                    count++;
                    numberOfError.Text = poch.ToString();
                    numberOfExample.Text = count.ToString();
                    Random second = new Random();
                    Random first = new Random();

                   int maxFirst = 10;
                    int maxSecond = 10;


                    int secondN = second.Next(2, maxSecond);
                    int firstN = secondN * first.Next(1, maxFirst / secondN);
                   if (mark.Text == "+")
                    {
                        int total = (firstN + secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                    if (mark.Text == "-")
                    {
                        int total = (firstN - secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                     if (mark.Text == "*")
                    {
                        int total = (firstN * secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();

                    }
                    if (zmark.Text == "/")
                    {
                        int residue = (firstN % secondN);
                        if (residue == 0)
                        {
                           int total = (firstN / secondN);
                        firstT.Text = firstN.ToString();
                        secondT.Text = secondN.ToString();
                        result.Text = total.ToString();
                        }

                    }
                }


                timer.Value = 0;
                shiftTimer.Start();
                if (poch == 4)
                {
                    mt.Stop();
                    timer.Value = 0;
                    shiftTimer.Stop();
                    MessageBox.Show("Game Over!");
                    end_Click(sender, e);

                }
            }
Posted
Updated 14-May-21 0:06am
v3
Comments
[no name] 12-May-21 14:03pm    
Somewhere you seem to be asking how to set a radio button's content - which you're already doing.
Member 15170612 13-May-21 2:24am    
seriously? where exactly?
#realJSOP 13-May-21 4:00am    
in the ShuffleText method.
Member 15170612 13-May-21 4:05am    
and in list can i assign values?
#realJSOP 15-May-21 7:37am    
I don't even know what you're trying to do.

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