c# - Math Logic Not Working -
I have a simple program to add two numbers with a text box answer (mathAnswer) is == That is, but when I enter the correct answer and I am getting the "wrong" from the replystatus label, the submit button? Does anyone know why?
using the system; Using System.Collections.Generic; Using System.Linq; Using System.Net; Using System.Windows; Using System.Windows.Controls; Using System.Windows.Navigation; Using Microsoft.Phone.Controls; Use of Microsoft phone. Shell; Namespace final project phone Virsn {public partial class math page: Phone Applications of Page {public Math page () {Random random = new Random (); Int randomNumber1 = random.Next (0, 10); Int randomNumber2 = random.Next (0, 5); Int answer = randomNumber1 + randomNumber2; Int counter = 0; Int Strike Control = 0; InitializeComponent (); String welcomeStreasting = (string) PhoneApplication service. Present. Location ["Enter name"]; Radiobutton HardRadio = (Radiobutton) Phone Results Service Present. Location ["radio_button2"]; Radio button easyRadio = (radio button) PhoneApplication Service. Present. Location ["radio_button1"]; WelcomeLabel.Text = "Welcome" + WelcomeString; // difficulty level label Text = "difficulty level:" + easy mode; ScoreLabel.Text = "Score:" + Counter; Striker ControlLabel Text = "wrong answer:" + strike controller; If ((bool easyRadio.IsChecked == true) {randomNumber1 = random.Next (0, 10); RandomNumber2 = random.Next (0, 5); } And if ((bool) hardradio.IsChecked == true) {randomNumber1 = random.Next (0, 6); RandomNumber2 = random.Next (0, 100); } If (Answer ToString () == Math Answers.Text) {answerStatusLabel.Text = "Right!"; } And if (Answer: toaster (!) = Math answer. Text) {answerStatusLabel.Text = "wrong!"; } Score Labels Text = "score:" + counter Toasting (); // if (difficultyList.SelectedIndex == 0) // {// mathQuestion.Text = Convert.ToString (randomNumber2) + "+" + Convert.ToString (randomNumber2); // add this line to num1Label.Text = Convert.ToString (RandomNumber1); // Add this line num2Label.Text = Convert.ToString (randomNumber2); // and this line mathSign.Text = "+"; //} // and if (difficulty list. Selected index == 1) // {// answer = randomNumber1 * randomNumber2; // num1Label.Text = Convert toString (randomNumber2); // Add this line // num2Label.Text = Convert Toasting (random number 1); // this line //}} private void TextBox_TextChanged (object sender, TextChangedEventArgs e) {} protected override void OnNavigatedTo (System.Windows.Navigation.NavigationEventArgs e) {} private void submitAnswer_Click (object sender, RoutedEventArgs e) {}} }
happens after you compare clicks on your users submit button. Therefore, compared to the code that button for button events must be taken into handler, like so:
private void submitAnswer_Click (object sender, RoutedEventArgs e) {if (answer.ToString () = = MathAnswer.Text) {answerStatusLabel.Text = "True!"; } And {answerStatusLabel.Text = "wrong!"; }}