lundi 31 octobre 2016

Else statement always executed c#

My Else statement is always being executed as well as the if statement.

If i log in as user 2 and any of the if or else-if statements are correct it will do that section of code but then it will always print "You can't send money to yourself" also.

Can anybody see what I've done wrong here as I've looked for the last 2 hours and can't see whats causing this?

if (loggedInUser == 2 && TaccountNumberTBox.Text == accountNo && TsortCodeTBox.Text == sortCode && amount <= balance2)
            {
                int bal;
                Int32.TryParse(TamountTBox.Text, out bal);
                balance2 = balance2 - bal;
                balance = balance + bal;
                MessageBox.Show("Funds sent");
                history = history + "£" + amount + " Sent to " + TnameTBox.Text + "\n";
                historyLbl.Text = history;

            }
            else if (loggedInUser == 2 && TaccountNumberTBox.Text != accountNo | TsortCodeTBox.Text != sortCode)
            {
                MessageBox.Show("The account you want to transfer to does not exist.");
            }
            else if (loggedInUser == 2 && amount > balance2)
            {
                MessageBox.Show("Insufficient funds");
            }
            else
            {
                MessageBox.Show("You can't send money to yourself");
            }

Aucun commentaire:

Enregistrer un commentaire