mardi 2 octobre 2018

Why does my code output "Incorrect" though the answer is correct?

I was just wanting some help with some of my code. I have it set up as such:

namespace AdditionTutorFIXED
{
    public partial class frmAdditionTutor : Form
{
    public int I = 0;
    public frmAdditionTutor()
    {
        InitializeComponent();
        Random rand = new Random();
        int NumberOne = rand.Next(500) + 100;
        int NumberTwo = rand.Next(500) + 100;
        lblEquation.Text = NumberOne.ToString() + " + " + NumberTwo.ToString() + "= ?";

    }

    private void btnSolve_Click(object sender, EventArgs e)
    {
        Random rand = new Random();
        int NumberOne = rand.Next(500) + 100;
        int NumberTwo = rand.Next(500) + 100;
        int TotalAmount = NumberOne + NumberTwo;
        int UserInputs = Convert.ToInt32(txtInput.Text);


        if ((NumberOne + NumberTwo) == UserInputs)
        {

            lblRightorWrong.Text = "Correct!";
            I++;
            txtAmountCorrect.Text = I.ToString();



        }
        else
        {
            lblRightorWrong.Text = "Incorrect!";
            I++;
            txtQuestionCount.Text = I.ToString();
        }





    }

What happens when I launched the program is that it gives the user an equation to solve. When they enter their problem, the code checks if it is correct or incorrect. If the answer is correct, I want it to display "Correct!" in the label and then add +1 to my "AmountCorrect" textbox.

The issue is that no matter if the user enters it correctly, the code thinks that it is incorrect and does not add on to the counter. I want my code to randomly display different variables to add to when the person gets the answer correct.

Aucun commentaire:

Enregistrer un commentaire