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
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:
List<string> list = new List<string> { "1", "2", "3" };
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)
{
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++;
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);
}
}