none
Testing the Values of multiple NumericUpDowns RRS feed

  • Question

  • hi so in a button i had the following block of code 
                if (bool1 = 0)
                {
                   if (bool2 = 0)
                    {
    
                        if (bool3 = 0)
                        {
                            MessageBox.Show("Please place a bet");
                        }
                        else
                        {
                            MessageBox.Show("Thank you for placing your bets");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Thank you for placing your bets");
                    }
                    
                }
                else
                {
                    MessageBox.Show("Thank you for placing your bets");
                }
    and so it would test the values of a total of 3 numericUpDowns, i want it so that when at least one of the values is greater than zero then it will say "Thank you for placing your bets". What is happening right now is that it is only saying "Thank you for placing your bets", if the first numericUpDown is greater than 1, if the other two are checked and the first one isn't, then it will say "Please place a bet"
    Wednesday, April 10, 2019 11:58 PM

Answers

  • Greetings Frozen_Nova.

    You are using the assignment operator (a single equals sign) where you should be using the equality operator (a double equals sign).

    if (bool1 == 0) // Use == instead of =. And same for the other two, obviously.

    • Marked as answer by Frozen_Nova Thursday, April 11, 2019 12:13 PM
    Thursday, April 11, 2019 1:10 AM
  • You are repeating yourself unnecessarily.  Just say

        if( (bool1 == 0) && (bool2 == 0) && (bool3 == 0) )
            MessageBox.Show( "Please place a bet." );
        else
            MessageBox.Show( "Thank you for placing your bets." );


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, April 11, 2019 7:13 AM

All replies

  • Greetings Frozen_Nova.

    You are using the assignment operator (a single equals sign) where you should be using the equality operator (a double equals sign).

    if (bool1 == 0) // Use == instead of =. And same for the other two, obviously.

    • Marked as answer by Frozen_Nova Thursday, April 11, 2019 12:13 PM
    Thursday, April 11, 2019 1:10 AM
  • You are repeating yourself unnecessarily.  Just say

        if( (bool1 == 0) && (bool2 == 0) && (bool3 == 0) )
            MessageBox.Show( "Please place a bet." );
        else
            MessageBox.Show( "Thank you for placing your bets." );


    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Thursday, April 11, 2019 7:13 AM